From acb7e049b8c70b9e6ad57e8601373f9c991a0da4 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 19 Jun 2014 23:01:15 -0400 Subject: implement sendmmsg and recvmmsg these are not pure syscall wrappers because they have to work around kernel API bugs on 64-bit archs. the workarounds could probably be made somewhat more efficient, but at the cost of more complexity. this may be revisited later. --- include/sys/socket.h | 11 +++++++++++ src/network/recvmmsg.c | 15 +++++++++++++++ src/network/sendmmsg.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/network/recvmmsg.c create mode 100644 src/network/sendmmsg.c diff --git a/include/sys/socket.h b/include/sys/socket.h index d7527911..b911d6ee 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -26,6 +26,17 @@ struct ucred uid_t uid; gid_t gid; }; + +struct mmsghdr +{ + struct msghdr msg_hdr; + unsigned int msg_len; +}; + +struct timespec; + +int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); +int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); #endif struct linger diff --git a/src/network/recvmmsg.c b/src/network/recvmmsg.c new file mode 100644 index 00000000..58b1b2f6 --- /dev/null +++ b/src/network/recvmmsg.c @@ -0,0 +1,15 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" + +int recvmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout) +{ +#if LONG_MAX > INT_MAX + struct mmsghdr *mh = msgvec; + unsigned int i; + for (i = vlen; i; i--, mh++) + mh->msg_hdr.__pad1 = mh->msg_hdr.__pad2 = 0; +#endif + return syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, timeout); +} diff --git a/src/network/sendmmsg.c b/src/network/sendmmsg.c new file mode 100644 index 00000000..ff9f8618 --- /dev/null +++ b/src/network/sendmmsg.c @@ -0,0 +1,29 @@ +#define _GNU_SOURCE +#include +#include +#include +#include "syscall.h" + +int sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags) +{ +#if LONG_MAX > INT_MAX + /* Can't use the syscall directly because the kernel has the wrong + * idea for the types of msg_iovlen, msg_controllen, and cmsg_len, + * and the cmsg blocks cannot be modified in-place. */ + int i; + if (vlen > IOV_MAX) vlen = IOV_MAX; /* This matches the kernel. */ + for (i=0; i