add_def HAVE_ARC4RANDOM
fi
+RECVMMSG_CODE='
+ struct mmsghdr hdr;
+ return !recvmmsg(0, &hdr, 1, MSG_DONTWAIT, 0);'
+if test_code 'recvmmsg()' 'sys/socket.h' '' "$EXTRA_LIBS" "$RECVMMSG_CODE"; then
+ add_def HAVE_RECVMMSG
+else
+ if test_code 'recvmmsg() with _GNU_SOURCE' 'sys/socket.h' '-D_GNU_SOURCE' \
+ "$EXTRA_LIBS" "$RECVMMSG_CODE"
+ then
+ add_def _GNU_SOURCE
+ add_def HAVE_RECVMMSG
+ fi
+fi
+
timepps_h=""
if [ $feat_refclock = "1" ] && [ $feat_pps = "1" ]; then
if test_code '<sys/timepps.h>' 'sys/timepps.h' '' '' ''; then
struct cmsghdr cmsgbuf[CMSGBUF_SIZE / sizeof (struct cmsghdr)];
};
+#ifdef HAVE_RECVMMSG
+#define MAX_RECV_MESSAGES 4
+#define MessageHeader mmsghdr
+#else
+/* Compatible with mmsghdr */
struct MessageHeader {
struct msghdr msg_hdr;
unsigned int msg_len;
};
#define MAX_RECV_MESSAGES 1
+#endif
/* Arrays of Message and MessageHeader */
static ARR_Instance recv_messages;
read_from_socket(int sock_fd, int event, void *anything)
{
/* This should only be called when there is something
- to read, otherwise it will block */
+ to read, otherwise it may block */
struct MessageHeader *hdr;
unsigned int i, n;
n = ARR_GetSize(recv_headers);
assert(n >= 1);
+#ifdef HAVE_RECVMMSG
+ status = recvmmsg(sock_fd, hdr, n, MSG_DONTWAIT, NULL);
+ if (status >= 0)
+ n = status;
+#else
n = 1;
status = recvmsg(sock_fd, &hdr[0].msg_hdr, 0);
if (status >= 0)
hdr[0].msg_len = status;
+#endif
if (status < 0) {
DEBUG_LOG(LOGF_NtpIO, "Could not receive from fd %d : %s", sock_fd,
SCMP_SYS(unlink),
/* Socket */
SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname),
- SCMP_SYS(recvfrom), SCMP_SYS(recvmsg), SCMP_SYS(sendmmsg),
- SCMP_SYS(sendmsg), SCMP_SYS(sendto),
+ SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg),
+ SCMP_SYS(sendmmsg), SCMP_SYS(sendmsg), SCMP_SYS(sendto),
/* TODO: check socketcall arguments */
SCMP_SYS(socketcall),
/* General I/O */