Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1437)

Unified Diff: fusl/src/network/sendmmsg.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/network/send.c ('k') | fusl/src/network/sendmsg.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/network/sendmmsg.c
diff --git a/fusl/src/network/sendmmsg.c b/fusl/src/network/sendmmsg.c
new file mode 100644
index 0000000000000000000000000000000000000000..eeae1d0a5822503f5c572a46e3d3696f6c95b1b9
--- /dev/null
+++ b/fusl/src/network/sendmmsg.c
@@ -0,0 +1,30 @@
+#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. */
+ if (!vlen) return 0;
+ 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
+}
« no previous file with comments | « fusl/src/network/send.c ('k') | fusl/src/network/sendmsg.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698