diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-07-20 12:24:12 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-07-20 12:24:12 +0000 |
commit | d68c3647e69cce6aaf4fd3d94e3eb33e3125b31c (patch) | |
tree | 18badf732631438ed7a6325d9634180270da6332 /src/libunixonacid | |
parent | e1dd693e2ac3c0fb1d42ea0e664021b4672465e6 (diff) | |
download | skalibs-d68c3647e69cce6aaf4fd3d94e3eb33e3125b31c.tar.xz |
Add ipc_timed_send
Diffstat (limited to 'src/libunixonacid')
-rw-r--r-- | src/libunixonacid/ipc_timed_send.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libunixonacid/ipc_timed_send.c b/src/libunixonacid/ipc_timed_send.c new file mode 100644 index 0000000..9ba1e32 --- /dev/null +++ b/src/libunixonacid/ipc_timed_send.c @@ -0,0 +1,31 @@ +/* ISC license. */ + +#include <sys/socket.h> +#include <errno.h> +#include <skalibs/error.h> +#include <skalibs/tai.h> +#include <skalibs/iopause.h> +#include <skalibs/unix-timed.h> + + /* Yay MacOS */ +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + +int ipc_timed_send (int fd, char const *s, unsigned int len, tain_t const *deadline, tain_t *stamp) +{ + iopause_fd x = { .fd = fd, .events = IOPAUSE_WRITE, .revents = 0 } ; + for (;;) + { + register int r = iopause_stamp(&x, 1, deadline, stamp) ; + if (r < 0) return 0 ; + else if (!r) return (errno = ETIMEDOUT, 0) ; + else if (x.revents & IOPAUSE_WRITE) + { + if (send(fd, s, len, MSG_NOSIGNAL) == (int)len) break ; + if (!error_isagain(errno)) return 0 ; + } + else if (x.revents & IOPAUSE_EXCEPT) return (send(fd, s, len, MSG_NOSIGNAL) == (int)len) ; + } + return 1 ; +} |