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 --- doc/upgrade.html | 1 + package/deps.mak | 1 + src/include/skalibs/unix-timed.h | 3 +++ src/libunixonacid/ipc_timed_send.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 src/libunixonacid/ipc_timed_send.c 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 @@

in 2.3.10.0

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 +#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