diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
commit | 8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch) | |
tree | df55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/network/recvmmsg.c | |
parent | Initial commit. (diff) | |
download | wasi-libc-upstream/0.0_git20221206.8b7148f.tar.xz wasi-libc-upstream/0.0_git20221206.8b7148f.zip |
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/network/recvmmsg.c')
-rw-r--r-- | libc-top-half/musl/src/network/recvmmsg.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/network/recvmmsg.c b/libc-top-half/musl/src/network/recvmmsg.c new file mode 100644 index 0000000..2978e2f --- /dev/null +++ b/libc-top-half/musl/src/network/recvmmsg.c @@ -0,0 +1,39 @@ +#define _GNU_SOURCE +#include <sys/socket.h> +#include <limits.h> +#include <errno.h> +#include <time.h> +#include "syscall.h" + +#define IS32BIT(x) !((x)+0x80000000ULL>>32) +#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) + +hidden void __convert_scm_timestamps(struct msghdr *, socklen_t); + +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 +#ifdef SYS_recvmmsg_time64 + time_t s = timeout ? timeout->tv_sec : 0; + long ns = timeout ? timeout->tv_nsec : 0; + int r = __syscall_cp(SYS_recvmmsg_time64, fd, msgvec, vlen, flags, + timeout ? ((long long[]){s, ns}) : 0); + if (SYS_recvmmsg == SYS_recvmmsg_time64 || r!=-ENOSYS) + return __syscall_ret(r); + if (vlen > IOV_MAX) vlen = IOV_MAX; + socklen_t csize[vlen]; + for (int i=0; i<vlen; i++) csize[i] = msgvec[i].msg_hdr.msg_controllen; + r = __syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, + timeout ? ((long[]){CLAMP(s), ns}) : 0); + for (int i=0; i<r; i++) + __convert_scm_timestamps(&msgvec[i].msg_hdr, csize[i]); + return __syscall_ret(r); +#else + return syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, timeout); +#endif +} |