Module Name: src Committed By: christos Date: Fri Jun 22 18:28:38 UTC 2012
Modified Files: src/lib/libc/sys: Makefile.inc recv.2 send.2 Log Message: {send,recv}mmsg glue To generate a diff of this commit: cvs rdiff -u -r1.214 -r1.215 src/lib/libc/sys/Makefile.inc cvs rdiff -u -r1.31 -r1.32 src/lib/libc/sys/recv.2 cvs rdiff -u -r1.27 -r1.28 src/lib/libc/sys/send.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/sys/Makefile.inc diff -u src/lib/libc/sys/Makefile.inc:1.214 src/lib/libc/sys/Makefile.inc:1.215 --- src/lib/libc/sys/Makefile.inc:1.214 Thu Mar 8 16:59:28 2012 +++ src/lib/libc/sys/Makefile.inc Fri Jun 22 14:28:38 2012 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.214 2012/03/08 21:59:28 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.215 2012/06/22 18:28:38 christos Exp $ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # sys sources @@ -117,11 +117,11 @@ ASM= access.S acct.S \ __posix_chown.S __posix_fchown.S __posix_lchown.S \ __posix_rename.S profil.S \ __quotactl.S \ - rasctl.S readlinkat.S reboot.S recvfrom.S recvmsg.S rename.S \ + rasctl.S readlinkat.S reboot.S recvfrom.S recvmmsg.S recvmsg.S rename.S \ renameat.S revoke.S rmdir.S \ semconfig.S semget.S semop.S \ - sendmsg.S sendto.S setegid.S setcontext.S seteuid.S setgid.S \ - setgroups.S __setitimer50.S __setlogin.S setpgid.S \ + sendmmsg.S sendmsg.S sendto.S setegid.S setcontext.S seteuid.S \ + setgid.S setgroups.S __setitimer50.S __setlogin.S setpgid.S \ setpriority.S \ setregid.S setreuid.S setrlimit.S setsid.S setsockopt.S \ setuid.S __shmctl50.S shmdt.S shmget.S shutdown.S \ @@ -305,9 +305,9 @@ MLINKS+=pathconf.2 fpathconf.2 MLINKS+=pmc_control.2 pmc_get_info.2 MLINKS+=poll.2 pollts.2 MLINKS+=read.2 readv.2 read.2 pread.2 read.2 preadv.2 -MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 +MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 recv.2 recvmmsg.2 MLINKS+=select.2 pselect.2 -MLINKS+=send.2 sendmsg.2 send.2 sendto.2 +MLINKS+=send.2 sendmsg.2 send.2 sendto.2 send.2 sendmmsg.2 MLINKS+=setpgid.2 setpgrp.2 MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2 MLINKS+=shmat.2 shmdt.2 Index: src/lib/libc/sys/recv.2 diff -u src/lib/libc/sys/recv.2:1.31 src/lib/libc/sys/recv.2:1.32 --- src/lib/libc/sys/recv.2:1.31 Wed Feb 1 08:30:42 2012 +++ src/lib/libc/sys/recv.2 Fri Jun 22 14:28:38 2012 @@ -1,4 +1,4 @@ -.\" $NetBSD: recv.2,v 1.31 2012/02/01 13:30:42 wiz Exp $ +.\" $NetBSD: recv.2,v 1.32 2012/06/22 18:28:38 christos Exp $ .\" .\" Copyright (c) 1983, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -35,7 +35,8 @@ .Sh NAME .Nm recv , .Nm recvfrom , -.Nm recvmsg +.Nm recvmsg , +.Nm recvmmsg .Nd receive a message from a socket .Sh LIBRARY .Lb libc @@ -47,10 +48,13 @@ .Fn recvfrom "int s" "void * restrict buf" "size_t len" "int flags" "struct sockaddr * restrict from" "socklen_t * restrict fromlen" .Ft ssize_t .Fn recvmsg "int s" "struct msghdr *msg" "int flags" +.Ft int +.Fn recvmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "unsigned int flags" "struct timespec *timeout" .Sh DESCRIPTION -.Fn recvfrom -and +.Fn recvfrom , .Fn recvmsg +and +.FN recvmmsg are used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented. @@ -67,6 +71,50 @@ and modified on return to indicate the a address stored there. .Pp The +.Fn recvmmsg +call be used to receive multiple messages in the same call using an array of +.Fa mmsghdr +elements with the following form, as defined in +.Ao Pa sys/socket.h Ac : +.Pp +.Bd -literal +struct mmsghdr { + struct msghdr msg_hdr; /* the message to be sent */ + unsigned int msg_len; /* number of bytes received */ +}; +.Ed +.Pp +The +.Fa msg_len +member contains the number of bytes received for each +.Fa msg_hdr +member. +The array has +.Fa vlen +elements, which is limited to +.Dv 1024 . +If there is an error, a number fewer than +.Fa vlen +may be returned, and the error may be retrieved using +.Xr getsockopt 2 +with +.Dv SO_ERROR . +If the flag +.Dv MSG_WAITFORONE +is set in +.Fa flags +then the +.Fn recvmmsg +call will wait for one message, and set +.Dv MSG_DONTWAIT +for the rest. +If the +.Fa timeout +parameter is not NULL, then +.Fn recvmmsg +will return if that time is exceeded. +.Pp +The .Fn recv call is normally used only on a .Em connected @@ -79,8 +127,14 @@ with a nil parameter. As it is redundant, it may not be supported in future releases. .Pp -All three routines return the length of the message on successful +.Fn recv , +.Fn recvfrom +and +.Fn recvmsg +routines return the length of the message on successful completion. +.Fn recvmmsg +returns the number of messages received. If a message is too long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from (see @@ -231,10 +285,19 @@ for ancillary data. .Dv MSG_OOB is returned to indicate that expedited or out-of-band data were received. .Sh RETURN VALUES -These calls return the number of bytes received, or \-1 +The +.Fn recv , +.Fn recvfrom +and +.Fn recvmsg +calls return the number of bytes received, or \-1 if an error occurred. For connected sockets whose remote peer was shut down, 0 is returned when no more data is available. +The +.Fn recvmmsg +calls return the number of messages received, or \-1 +if an error occurred. .Sh ERRORS The calls fail if: .Bl -tag -width Er @@ -292,3 +355,9 @@ The .Fn recv function call appeared in .Bx 4.2 . +The +.Fn recvmmsg +function call appeared on +.Lx 2.6.32 +and +.Nx 7 . Index: src/lib/libc/sys/send.2 diff -u src/lib/libc/sys/send.2:1.27 src/lib/libc/sys/send.2:1.28 --- src/lib/libc/sys/send.2:1.27 Fri May 9 11:52:50 2008 +++ src/lib/libc/sys/send.2 Fri Jun 22 14:28:38 2012 @@ -1,4 +1,4 @@ -.\" $NetBSD: send.2,v 1.27 2008/05/09 15:52:50 christos Exp $ +.\" $NetBSD: send.2,v 1.28 2012/06/22 18:28:38 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,13 +29,14 @@ .\" .\" @(#)send.2 8.2 (Berkeley) 2/21/94 .\" -.Dd May 9, 2008 +.Dd June 7, 2012 .Dt SEND 2 .Os .Sh NAME .Nm send , .Nm sendto , -.Nm sendmsg +.Nm sendmsg , +.Nm sendmmsg .Nd send a message from a socket .Sh LIBRARY .Lb libc @@ -47,21 +48,55 @@ .Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen" .Ft ssize_t .Fn sendmsg "int s" "const struct msghdr *msg" "int flags" +.Ft int +.Fn sendmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "unsigned int flags" .Sh DESCRIPTION .Fn send , .Fn sendto , +.Fn sendmsg , and -.Fn sendmsg +.Fn sendmmsg are used to transmit a message to another socket. .Fn send may be used only when the socket is in a .Em connected state, while -.Fn sendto -and +.Fn sendto , .Fn sendmsg +and +.Fn sendmmsg may be used at any time. .Pp +The +.Fn sendmmsg +call be used to send multiple messages in the same call using an array of +.Fa mmsghdr +elements with the following form, as defined in +.Ao Pa sys/socket.h Ac : +.Pp +.Bd -literal +struct mmsghdr { + struct msghdr msg_hdr; /* the message to be sent */ + unsigned int msg_len; /* number of bytes transmitted */ +}; +.Ed +.Pp +The +.Fa msg_len +member contains the number of bytes sent for each +.Fa msg_hdr +member. +The array has +.Fa vlen +elements, which is limited to +.Dv 1024 . +If there is an error, a number fewer than +.Fa vlen +may be returned, and the error may be retrieved using +.Xr getsockopt 2 +with +.Dv SO_ERROR . +.Pp The address of the target is given by .Fa to with @@ -90,6 +125,9 @@ or .Xr poll 2 call may be used to determine when it is possible to send more data. +Unfortunately this does not work when the interface queue which is used to +send the message is full, and the call returns +.Er ENOBUFS . .Pp The .Fa flags @@ -139,13 +177,23 @@ is used to prevent generation when writing a socket that may be closed. .Sh RETURN VALUES -The call returns the number of characters sent, or \-1 +The +.Fn send , +.Fn sendto , +and +.Fn sendmsg +calls return the number of characters sent, or \-1 if an error occurred. +The +.Fn sendmmsg +call returns the number of messages sent, or \-1 +if an error occured. .Sh ERRORS .Fn send , .Fn sendto , +.Fn sendmsg , and -.Fn sendmsg +.Fn sendmmsg fail if: .Bl -tag -width Er .It Bq Er EBADF @@ -196,6 +244,8 @@ A destination address was specified and .El .Pp .Fn sendmsg +and +.Fn sendmmsg will also fail if: .Bl -tag -width Er .It Bq Er EMSGSIZE @@ -219,3 +269,9 @@ The .Fn send function call appeared in .Bx 4.2 . +The +.Fn sendmmsg +function call appeared in +.Lx 3.0 +and +.Nx 7 .