ipc_timed_send.c (802B)
1 /* ISC license. */ 2 3 #include <skalibs/nonposix.h> 4 5 #include <sys/socket.h> 6 #include <errno.h> 7 8 #include <skalibs/error.h> 9 #include <skalibs/iopause.h> 10 #include <skalibs/unix-timed.h> 11 #include <skalibs/posixishard.h> 12 13 int ipc_timed_send (int fd, char const *s, size_t len, tain const *deadline, tain *stamp) 14 { 15 iopause_fd x = { .fd = fd, .events = IOPAUSE_WRITE, .revents = 0 } ; 16 for (;;) 17 { 18 int r = iopause_stamp(&x, 1, deadline, stamp) ; 19 if (r < 0) return 0 ; 20 else if (!r) return (errno = ETIMEDOUT, 0) ; 21 else if (x.revents & IOPAUSE_WRITE) 22 { 23 if (send(fd, s, len, MSG_NOSIGNAL) == (ssize_t)len) break ; 24 if (!error_isagain(errno)) return 0 ; 25 } 26 else if (x.revents & IOPAUSE_EXCEPT) return (send(fd, s, len, MSG_NOSIGNAL) == (ssize_t)len) ; 27 } 28 return 1 ; 29 }