OSDN Git Service

(split) LDP: Update original to v3.37.
[linuxjm/LDP_man-pages.git] / original / man2 / recvmmsg.2
1 .\" Copyright (C) 2011 by Andi Kleen <andi@firstfloor.org>
2 .\" and Copyright (c) 2011 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" FIXME: This page could be improved with an example program.
25 .\"
26 .TH RECVMMSG 2 2011-10-04 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 recvmmsg \- receive multiple messages on a socket
29 .SH SYNOPSIS
30 .nf
31 .B "#define _GNU_SOURCE"
32 .BI "#include <sys/socket.h>"
33
34 .BI "int recvmmsg(int " sockfd ", struct mmsghdr *" msgvec \
35 ", unsigned int " vlen ","
36 .br
37 .BI "             unsigned int " flags ", struct timespec *" timeout ");"
38 .fi
39 .SH DESCRIPTION
40 The
41 .BR recvmmsg ()
42 system call is an extension of
43 .BR recvmsg (2)
44 that allows the caller to receive multiple messages from a socket
45 using a single system call.
46 (This has performance benefits for some applications.)
47 A further extension over
48 .BR recvmsg (2)
49 is support for a timeout on the receive operation.
50
51 The
52 .I sockfd
53 argument is the file descriptor of the socket to receive data from.
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 received bytes for header */
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 recvmsg (2).
84 The
85 .I msg_len
86 field is the number of bytes returned for the message in the entry.
87 This field has the same value as the return value of a single
88 .BR recvmsg (2)
89 on the header.
90
91 The
92 .I flags
93 argument contains flags ORed together.
94 The flags are the same as documented for
95 .BR recvmsg (2),
96 with the following addition:
97 .TP
98 .B MSG_WAITFORONE
99 Turns on
100 .B MSG_DONTWAIT
101 after the first message has been received.
102 .PP
103 The
104 .I timeout
105 argument points to a
106 .I struct timespec
107 (see
108 .BR clock_gettime (2))
109 defining a timeout (seconds plus nanoseconds) for the receive operation.
110 If
111 .I timeout
112 is
113 .I NULL
114 then the operation blocks indefinitely.
115
116 A blocking
117 .BR recvmmsg ()
118 call blocks until
119 .I vlen
120 messages have been received
121 or until the timeout expires.
122 A nonblocking call reads as many messages as are available
123 (up to the limit specified by
124 .IR vlen )
125 and returns immediately.
126
127 On return from
128 .BR recvmmsg (),
129 successive elements of
130 .IR msgvec
131 are updated to contain information about each received message:
132 .I msg_len
133 contains the size of the received message;
134 the subfields of
135 .I msg_hdr
136 are updated as described in
137 .BR recvmsg (2).
138 The return value of the call indicates the number of elements of
139 .I msgvec
140 that have been updated.
141 .SH RETURN VALUE
142 On success,
143 .BR recvmmsg ()
144 returns the number of messages received in
145 .IR msgvec ;
146 on error, \-1 is returned, and
147 .I errno
148 is set to indicate the error.
149 .SH ERRORS
150 Errors are as for
151 .BR recvmsg (2).
152 In addition, the following error can occur:
153 .TP
154 .B EINVAL
155 .I timeout
156 is invalid.
157 .SH VERSIONS
158 The
159 .BR recvmmsg ()
160 system call was added in Linux 2.6.32.
161 Support in glibc was added in version 2.12.
162 .SH CONFORMING TO
163 .BR recvmmsg ()
164 is Linux-specific.
165 .SH SEE ALSO
166 .BR clock_gettime (2),
167 .BR recvmsg (2),
168 .BR sendmmsg (2),
169 .BR sendmsg (2),
170 .BR socket (2),
171 .BR socket (7)