summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-21 00:26:40 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-21 00:26:40 +0000
commit23bdcb4ad4ef19d99b729e5282fd15df6300a3b5 (patch)
treebc1976b67844d3070b0cd2bbecf5103ece86024d
parent828159d33b8ced9e016470c61ffd66bbef048e06 (diff)
downloadskalibs-23bdcb4ad4ef19d99b729e5282fd15df6300a3b5.tar.xz
So the non-portable MSG_DONTWAIT may alleviate the problem... might
as well use it on architectures that support it.
-rwxr-xr-xconfigure3
-rw-r--r--src/libunixonacid/unixmessage_receive.c23
-rw-r--r--src/sysdeps/trymsgdontwait.c17
-rw-r--r--src/sysdeps/trynbwaitall.c (renamed from src/sysdeps/tryokwaitall.c)4
4 files changed, 32 insertions, 15 deletions
diff --git a/configure b/configure
index ba4439a..389b31b 100755
--- a/configure
+++ b/configure
@@ -442,7 +442,8 @@ EOF
choose cl getpeerucred GETPEERUCRED 'getpeerucred()'
choose cl ipv6 IPV6 'IPv6 support' $socket_lib
choose clr malloc0 MALLOC0 'non-NULL malloc(0)'
- choose clr okwaitall OKWAITALL 'a usable MSG_WAITALL flag'
+ choose c msgdontwait MSGDONTWAIT 'MSG_DONTWAIT'
+ choose clr nbwaitall NBWAITALL 'non-blocking MSG_WAITALL'
choose cl openat OPENAT 'openat()'
choose cl linkat LINKAT 'linkat()'
choose clr pipe2 PIPE2 'pipe2()'
diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c
index 502b523..5c80082 100644
--- a/src/libunixonacid/unixmessage_receive.c
+++ b/src/libunixonacid/unixmessage_receive.c
@@ -14,19 +14,18 @@
#include <skalibs/siovec.h>
#include <skalibs/unixmessage.h>
-#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
+static int const awesomeflags =
+#ifdef SKALIBS_HASMSGDONTWAIT
+ MSG_WAITALL | MSG_DONTWAIT
+#elif defined (SKALIBS_HASNBWAITALL)
+ MSG_WAITALL
#else
-# ifdef SKALIBS_HASCMSGCLOEXEC
-# define RECV(fd, hdr) recvmsg(fd, (hdr), MSG_CMSG_CLOEXEC)
-# else
-# define RECV(fd, hdr) recvmsg(fd, (hdr), 0)
-# endif
+ 0
#endif
+#ifdef SKALIBS_HASCMSGCLOEXEC
+ | MSG_CMSG_CLOEXEC
+#endif
+ ;
static int unixmessage_receiver_fill (unixmessage_receiver_t *b)
{
@@ -51,7 +50,7 @@ static int unixmessage_receiver_fill (unixmessage_receiver_t *b)
cbuffer_wpeek(&b->mainb, v) ;
iovec_from_siovec(iov, v, 2) ;
}
- r = RECV(b->fd, &msghdr) ;
+ r = recvmsg(b->fd, &msghdr, awesomeflags) ;
if (r <= 0) return r ;
{
struct cmsghdr *c = CMSG_FIRSTHDR(&msghdr) ;
diff --git a/src/sysdeps/trymsgdontwait.c b/src/sysdeps/trymsgdontwait.c
new file mode 100644
index 0000000..0c8ad15
--- /dev/null
+++ b/src/sysdeps/trymsgdontwait.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
+#ifndef _XPG4_2
+# define _XPG4_2
+#endif
+
+#ifndef _BSD_SOURCE
+#define _BSD_SOURCE
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int value = MSG_DONTWAIT ;
diff --git a/src/sysdeps/tryokwaitall.c b/src/sysdeps/trynbwaitall.c
index 15721b5..0f55080 100644
--- a/src/sysdeps/tryokwaitall.c
+++ b/src/sysdeps/trynbwaitall.c
@@ -53,8 +53,8 @@ static int child (int p, int fd)
if (write(p, "", 1) < 1) return 111 ; /* sync with the parent */
if (select(fd+1, &rfds, 0, 0, 0) < 1) return 111 ;
- /* On buggy systems, the following recvmsg will block, despite
- setting the fd non-blocking */
+ /* The following recvmsg may block, despite setting the fd
+ non-blocking. That is what we're testing. */
if (recvmsg(fd, &msg, MSG_WAITALL) < 1) return 111 ;
if (write(p, "", 1) < 1) return 111 ;