From db7f4d2c1ef70334af4cb8c1980f47d8a9f69249 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 20 Dec 2014 22:25:08 +0000 Subject: Found the BSD unixmessage bug. recvmsg(..., MSG_WAITALL) blocks until buffer full or socket shutdown on BSD, *even if the socket is nonblocking*. So I added an "okwaitall" sysdeps, and won't set MSG_WAITALL on retarded systems. --- src/libunixonacid/unixmessage_receive.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/libunixonacid/unixmessage_receive.c') diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c index a86ae10..502b523 100644 --- a/src/libunixonacid/unixmessage_receive.c +++ b/src/libunixonacid/unixmessage_receive.c @@ -1,6 +1,5 @@ /* ISC license. */ -#define _XPG4_2 #include #include #include @@ -15,6 +14,20 @@ #include #include +#ifdef SKALIBS_HASOKWAITALL +# ifdef SKALIBS_HASCMSGCLOEXEC +# define RECV(fd, hdr) recvmsg(fd, (hdr), MSG_WAITALL | MSG_CMSG_CLOEXEC) +# else +# define RECV(fd, hdr) recvmsg(fd, (hdr), MSG_WAITALL) +# endif +#else +# ifdef SKALIBS_HASCMSGCLOEXEC +# define RECV(fd, hdr) recvmsg(fd, (hdr), MSG_CMSG_CLOEXEC) +# else +# define RECV(fd, hdr) recvmsg(fd, (hdr), 0) +# endif +#endif + static int unixmessage_receiver_fill (unixmessage_receiver_t *b) { char ancilbuf[CMSG_SPACE(b->auxb.a - 1)] ; @@ -38,11 +51,7 @@ static int unixmessage_receiver_fill (unixmessage_receiver_t *b) cbuffer_wpeek(&b->mainb, v) ; iovec_from_siovec(iov, v, 2) ; } -#ifdef SKALIBS_HASCMSGCLOEXEC - r = recvmsg(b->fd, &msghdr, MSG_WAITALL | MSG_CMSG_CLOEXEC) ; -#else - r = recvmsg(b->fd, &msghdr, MSG_WAITALL) ; -#endif + r = RECV(b->fd, &msghdr) ; if (r <= 0) return r ; { struct cmsghdr *c = CMSG_FIRSTHDR(&msghdr) ; -- cgit v1.2.3