skalibs

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

ipc_timed_connect.c (676B)


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