OSDN Git Service

(split) LDP: Update original to v3.37.
[linuxjm/LDP_man-pages.git] / original / man2 / sendmmsg.2
1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" with some material from a draft by
3 .\" Stephan Mueller <stephan.mueller@atsec.com>
4 .\" in turn based on Andi Kleen's recvmmsg.2 page.
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" FIXME Adding an example program would improve this page
27 .\"
28 .TH SENDMMSG 2 2012-02-27 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 sendmmsg \- send multiple messages on a socket
31 .SH SYNOPSIS
32 .nf
33 .B "#define _GNU_SOURCE"
34 .BI "#include <sys/socket.h>"
35
36 .BI "int sendmmsg(int " sockfd ", struct mmsghdr *" msgvec \
37 ", unsigned int " vlen ","
38 .BI "             unsigned int " flags ");"
39 .fi
40 .SH DESCRIPTION
41 The
42 .BR sendmmsg ()
43 system call is an extension of
44 .BR sendmsg (2)
45 that allows the caller to transmit multiple messages on a socket
46 using a single system call.
47 (This has performance benefits for some applications.)
48 .\" See commit 228e548e602061b08ee8e8966f567c12aa079682
49
50 The
51 .I sockfd
52 argument is the file descriptor of the socket
53 on which data is to be transmitted.
54
55 The
56 .I msgvec
57 argument is a pointer to an array of
58 .I mmsghdr
59 structures.
60 The size of this array is specified in
61 .IR vlen .
62
63 The
64 .I mmsghdr
65 structure is defined in
66 .I <sys/socket.h>
67 as:
68
69 .in +4n
70 .nf
71 struct mmsghdr {
72     struct msghdr msg_hdr;  /* Message header */
73     unsigned int  msg_len;  /* Number of bytes transmitted */
74 };
75 .fi
76 .in
77 .PP
78 The
79 .I msg_hdr
80 field is a
81 .I msghdr
82 structure, as described in
83 .BR sendmsg (2).
84 The
85 .I msg_len
86 field is used to return the number of bytes sent from the message in
87 .IR msg_hdr
88 (i.e., the same as the return value from a single
89 .BR sendmsg (2)
90 call).
91
92 The
93 .I flags
94 argument contains flags ORed together.
95 The flags are the same as for
96 .BR sendmsg (2).
97
98 A blocking
99 .BR sendmmsg ()
100 call blocks until
101 .I vlen
102 messages have been sent.
103 A nonblocking call sends as many messages as possible
104 (up to the limit specified by
105 .IR vlen )
106 and returns immediately.
107
108 On return from
109 .BR sendmmsg (),
110 the
111 .I msg_len
112 fields of successive elements of
113 .IR msgvec
114 are updated to contain the number of bytes transmitted from the corresponding
115 .IR msg_hdr .
116 The return value of the call indicates the number of elements of
117 .I msgvec
118 that have been updated.
119 .SH RETURN VALUE
120 On success,
121 .BR sendmmsg ()
122 returns the number of messages sent from
123 .IR msgvec ;
124 if this is less than
125 .IR vlen ,
126 the caller can retry with a further
127 .BR sendmmsg ()
128 call to send the remaining messages.
129
130 On error, \-1 is returned, and
131 .I errno
132 is set to indicate the error.
133 .SH ERRORS
134 Errors are as for
135 .BR sendmsg (2).
136 An error is returned only if no datagrams could be sent.
137 .\" commit 728ffb86f10873aaf4abd26dde691ee40ae731fe
138 .\"     ... only return an error if no datagrams could be sent.
139 .\"     If less than the requested number of messages were sent, the application
140 .\"     must retry starting at the first failed one and if the problem is
141 .\"     persistent the error will be returned.
142 .\"
143 .\"     This matches the behaviour of other syscalls like read/write - it
144 .\"     is not an error if less than the requested number of elements are sent.
145 .SH VERSIONS
146 The
147 .BR sendmmsg ()
148 system call was added in Linux 3.0.
149 Support in glibc was added in version 2.14.
150 .SH CONFORMING TO
151 .BR sendmmsg ()
152 is Linux-specific.
153 .SH NOTES
154 The value specified in
155 .I vlen
156 is capped to
157 .B UIO_MAXIOV
158 (1024).
159 .\" commit 98382f419f32d2c12d021943b87dea555677144b
160 .\"     net: Cap number of elements for sendmmsg
161 .\"
162 .\"     To limit the amount of time we can spend in sendmmsg, cap the
163 .\"     number of elements to UIO_MAXIOV (currently 1024).
164 .\"
165 .\"     For error handling an application using sendmmsg needs to retry at
166 .\"     the first unsent message, so capping is simpler and requires less
167 .\"     application logic than returning EINVAL.
168 .SH SEE ALSO
169 .BR recvmmsg (2),
170 .BR sendmsg (2),
171 .BR socket (2),
172 .BR socket (7)