| OLD | NEW |
| 1 #define _GNU_SOURCE | 1 #define _GNU_SOURCE |
| 2 #include <sys/socket.h> | 2 #include <sys/socket.h> |
| 3 #include <limits.h> | 3 #include <limits.h> |
| 4 #include <errno.h> | 4 #include <errno.h> |
| 5 #include "syscall.h" | 5 #include "syscall.h" |
| 6 | 6 |
| 7 int sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int fla
gs) | 7 int sendmmsg(int fd, |
| 8 { | 8 struct mmsghdr* msgvec, |
| 9 unsigned int vlen, |
| 10 unsigned int flags) { |
| 9 #if LONG_MAX > INT_MAX | 11 #if LONG_MAX > INT_MAX |
| 10 » /* Can't use the syscall directly because the kernel has the wrong | 12 /* Can't use the syscall directly because the kernel has the wrong |
| 11 » * idea for the types of msg_iovlen, msg_controllen, and cmsg_len, | 13 * idea for the types of msg_iovlen, msg_controllen, and cmsg_len, |
| 12 » * and the cmsg blocks cannot be modified in-place. */ | 14 * and the cmsg blocks cannot be modified in-place. */ |
| 13 » int i; | 15 int i; |
| 14 » if (vlen > IOV_MAX) vlen = IOV_MAX; /* This matches the kernel. */ | 16 if (vlen > IOV_MAX) |
| 15 » if (!vlen) return 0; | 17 vlen = IOV_MAX; /* This matches the kernel. */ |
| 16 » for (i=0; i<vlen; i++) { | 18 if (!vlen) |
| 17 » » /* As an unfortunate inconsistency, the sendmmsg API uses | 19 return 0; |
| 18 » » * unsigned int for the resulting msg_len, despite sendmsg | 20 for (i = 0; i < vlen; i++) { |
| 19 » » * returning ssize_t. However Linux limits the total bytes | 21 /* As an unfortunate inconsistency, the sendmmsg API uses |
| 20 » » * sent by sendmsg to INT_MAX, so the assignment is safe. */ | 22 * unsigned int for the resulting msg_len, despite sendmsg |
| 21 » » ssize_t r = sendmsg(fd, &msgvec[i].msg_hdr, flags); | 23 * returning ssize_t. However Linux limits the total bytes |
| 22 » » if (r < 0) goto error; | 24 * sent by sendmsg to INT_MAX, so the assignment is safe. */ |
| 23 » » msgvec[i].msg_len = r; | 25 ssize_t r = sendmsg(fd, &msgvec[i].msg_hdr, flags); |
| 24 » } | 26 if (r < 0) |
| 27 goto error; |
| 28 msgvec[i].msg_len = r; |
| 29 } |
| 25 error: | 30 error: |
| 26 » return i ? i : -1; | 31 return i ? i : -1; |
| 27 #else | 32 #else |
| 28 » return syscall_cp(SYS_sendmmsg, fd, msgvec, vlen, flags); | 33 return syscall_cp(SYS_sendmmsg, fd, msgvec, vlen, flags); |
| 29 #endif | 34 #endif |
| 30 } | 35 } |
| OLD | NEW |