diff options
author | Rich Felker <dalias@aerifal.cx> | 2014-06-19 23:01:15 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2014-06-19 23:01:15 -0400 |
commit | acb7e049b8c70b9e6ad57e8601373f9c991a0da4 (patch) | |
tree | ecba8b37b99eafecade1f60b5b8e14e4e6d4be73 /src/network/sendmmsg.c | |
parent | 39201d07e41ca4cf5f8c35d4663767aa3f75208f (diff) | |
download | musl-acb7e049b8c70b9e6ad57e8601373f9c991a0da4.tar.gz musl-acb7e049b8c70b9e6ad57e8601373f9c991a0da4.tar.bz2 musl-acb7e049b8c70b9e6ad57e8601373f9c991a0da4.tar.xz musl-acb7e049b8c70b9e6ad57e8601373f9c991a0da4.zip |
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.
Diffstat (limited to 'src/network/sendmmsg.c')
-rw-r--r-- | src/network/sendmmsg.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <sys/socket.h> +#include <limits.h> +#include <errno.h> +#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<vlen; i++) { + /* As an unfortunate inconsistency, the sendmmsg API uses + * unsigned int for the resulting msg_len, despite sendmsg + * returning ssize_t. However Linux limits the total bytes + * sent by sendmsg to INT_MAX, so the assignment is safe. */ + ssize_t r = sendmsg(fd, &msgvec[i].msg_hdr, flags); + if (r < 0) goto error; + msgvec[i].msg_len = r; + } +error: + return i ? i : -1; +#else + return syscall_cp(SYS_sendmmsg, fd, msgvec, vlen, flags); +#endif +} |