From d68c3647e69cce6aaf4fd3d94e3eb33e3125b31c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 20 Jul 2016 12:24:12 +0000 Subject: Add ipc_timed_send --- src/libunixonacid/ipc_timed_send.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/libunixonacid/ipc_timed_send.c (limited to 'src/libunixonacid/ipc_timed_send.c') 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 +#include +#include +#include +#include +#include + + /* 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 ; +} -- cgit v1.2.3