skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

socket_waitconn.c (566B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 
      5 #include <skalibs/allreadwrite.h>
      6 #include <skalibs/iopause.h>
      7 #include <skalibs/socket.h>
      8 
      9 int socket_waitconn (int s, tain const *deadline, tain *stamp)
     10 {
     11   iopause_fd x = { s, IOPAUSE_WRITE, 0 } ;
     12   for (;;)
     13   {
     14     int r = iopause_stamp(&x, 1, deadline, stamp) ;
     15     if (r < 0) return 0 ;
     16     if (!r) return (errno = ETIMEDOUT, 0) ;
     17     if (x.revents & IOPAUSE_WRITE) break ;
     18     if (x.revents & IOPAUSE_EXCEPT)
     19     {
     20       fd_write(s, "", 1) ; /* sets errno */
     21       return 0 ;
     22     }
     23   }
     24   return socket_connected(s) ;
     25 }