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 | |
parent | e1dd693e2ac3c0fb1d42ea0e664021b4672465e6 (diff) | |
download | skalibs-d68c3647e69cce6aaf4fd3d94e3eb33e3125b31c.tar.xz |
Add ipc_timed_send
-rw-r--r-- | doc/upgrade.html | 1 | ||||
-rw-r--r-- | package/deps.mak | 1 | ||||
-rw-r--r-- | src/include/skalibs/unix-timed.h | 3 | ||||
-rw-r--r-- | src/libunixonacid/ipc_timed_send.c | 31 |
4 files changed, 36 insertions, 0 deletions
diff --git a/doc/upgrade.html b/doc/upgrade.html index 143983b..fd1a05f 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -22,6 +22,7 @@ <ul> <li> More support for advanced fd callbacks in <tt>unixmessage_sender</tt> and <tt>unixconnection</tt>. </li> + <li> <tt>ipc_timed_send()</tt>. </li> </ul> <h2> in 2.3.10.0 </h2> diff --git a/package/deps.mak b/package/deps.mak index 404bede..56a9383 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -727,6 +727,7 @@ src/libunixonacid/dd_commit.o src/libunixonacid/dd_commit.lo: src/libunixonacid/ src/libunixonacid/dd_commit_devino.o src/libunixonacid/dd_commit_devino.lo: src/libunixonacid/dd_commit_devino.c src/include/skalibs/uint64.h src/include/skalibs/unix-transactional.h src/libunixonacid/dd_open_read.o src/libunixonacid/dd_open_read.lo: src/libunixonacid/dd_open_read.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/dd_open_write.o src/libunixonacid/dd_open_write.lo: src/libunixonacid/dd_open_write.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h +src/libunixonacid/ipc_timed_send.o src/libunixonacid/ipc_timed_send.lo: src/libunixonacid/ipc_timed_send.c src/include/skalibs/error.h src/include/skalibs/iopause.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h src/libunixonacid/kolbak_call.o src/libunixonacid/kolbak_call.lo: src/libunixonacid/kolbak_call.c src/include/skalibs/kolbak.h src/include/skalibs/unixmessage.h src/libunixonacid/kolbak_enqueue.o src/libunixonacid/kolbak_enqueue.lo: src/libunixonacid/kolbak_enqueue.c src/include/skalibs/kolbak.h src/include/skalibs/unixmessage.h src/libunixonacid/kolbak_queue_init.o src/libunixonacid/kolbak_queue_init.lo: src/libunixonacid/kolbak_queue_init.c src/include/skalibs/kolbak.h diff --git a/src/include/skalibs/unix-timed.h b/src/include/skalibs/unix-timed.h index 5fad179..c3ae4cd 100644 --- a/src/include/skalibs/unix-timed.h +++ b/src/include/skalibs/unix-timed.h @@ -33,4 +33,7 @@ extern int timed_getlnmax (buffer *, char *, unsigned int, unsigned int *, char, extern int netstring_timed_get (buffer *, stralloc *, tain_t const *, tain_t *) ; #define netstring_timed_get_g(b, sa, deadline) netstring_timed_get(b, sa, (deadline), &STAMP) +extern int ipc_timed_send (int, char const *, unsigned int, tain_t const *, tain_t *) ; +#define ipc_timed_send_g(fd, s, len, deadline) ipc_timed_send(fd, s, len, (deadline), &STAMP) + #endif 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 ; +} |