aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/sendmmsg.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-05-28 01:43:20 -0400
committerUlrich Drepper <drepper@gmail.com>2011-05-28 01:43:20 -0400
commitf1f929d74a08d6f973cec20e311401586f408d35 (patch)
treeaad431c8f39d6474212303226cc49dd2a642d99b /sysdeps/unix/sysv/linux/sendmmsg.c
parentce67228d570d2df88d74184e5e3618a5b2ef8704 (diff)
downloadglibc-f1f929d74a08d6f973cec20e311401586f408d35.tar
glibc-f1f929d74a08d6f973cec20e311401586f408d35.tar.gz
glibc-f1f929d74a08d6f973cec20e311401586f408d35.tar.bz2
glibc-f1f929d74a08d6f973cec20e311401586f408d35.zip
Add sendmmsg syscall
Diffstat (limited to 'sysdeps/unix/sysv/linux/sendmmsg.c')
-rw-r--r--sysdeps/unix/sysv/linux/sendmmsg.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/sendmmsg.c b/sysdeps/unix/sysv/linux/sendmmsg.c
new file mode 100644
index 0000000000..d8099878a0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sendmmsg.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_sendmmsg
+int
+sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (sendmmsg, 4, fd, vmessages, vlen, flags);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (sendmmsg, 4, fd, vmessages, vlen, flags);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+#elif defined __NR_socketcall
+# ifndef __ASSUME_SENDMMSG
+extern int __internal_sendmmsg (int fd, struct mmsghdr *vmessages,
+ unsigned int vlen, int flags)
+ attribute_hidden;
+
+static int have_sendmmsg;
+
+int
+sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+ if (__builtin_expect (have_sendmmsg >= 0, 1))
+ {
+ int ret = __internal_sendmmsg (fd, vmessages, vlen, flags);
+ /* The kernel returns -EINVAL for unknown socket operations.
+ We need to convert that error to an ENOSYS error. */
+ if (__builtin_expect (ret < 0, 0)
+ && have_sendmmsg == 0
+ && errno == EINVAL)
+ {
+ /* Try another call, this time with an invalid file
+ descriptor and all other parameters cleared. This call
+ will not cause any harm and it will return
+ immediately. */
+ ret = __internal_sendmmsg (-1, 0, 0, 0);
+ if (errno == EINVAL)
+ {
+ have_sendmmsg = -1;
+ __set_errno (ENOSYS);
+ }
+ else
+ {
+ have_sendmmsg = 1;
+ __set_errno (EINVAL);
+ }
+ return -1;
+ }
+ return ret;
+ }
+ __set_errno (ENOSYS);
+ return -1;
+}
+# else
+/* When __ASSUME_SENDMMSG sendmmsg is defined in internal_sendmmsg.S. */
+# endif
+#else
+int
+sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+ __set_errno (ENOSYS);
+ return -1;
+}
+stub_warning (sendmmsg)
+#endif