Repository navigation
Expand file tree
/
Copy pathrecvmsg.2
More file actions
306 lines (306 loc) · 8.35 KB
/
Copy pathrecvmsg.2
File metadata and controls
306 lines (306 loc) · 8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
.TH RECVMSG 2 2024-11-11 "Homa" "Linux Programmer's Manual"
.SH NAME
recvmsg \- receive a Homa message
.SH SYNOPSIS
.nf
.B #include <homa.h>
.PP
.BI "ssize_t recvmsg(int " sockfd ", const struct msghdr *" msg ", int " flags );
.fi
.SH DESCRIPTION
The
.B recvmsg
kernel call is used to receive messages (both requests and responses)
on Homa sockets. The
.I sockfd
argument must refer to a Homa socket. The
.I msg
argument describes which incoming messages are of interest and is
used to return information about the message that is received. The
.I flags
argument is not used except for its
.B MSG_DONTWAIT
bit, which can be used to request nonblocking behavior.
.PP
The
.B msg
argument must point to a structure of the following type:
.PP
.in +4n
.ps -1
.vs -2
.EX
struct msghdr {
void *msg_name; /* Address of sender (sockaddr_in or
* sockaddr_in6) will be stored here. If NULL,
* no address info is returned. */
socklen_t msg_namelen; /* Number of bytes available at *msg_name. */
struct iovec *msg_iov; /* Not used. */
size_t msg_iovlen; /* Not used. */
void *msg_control; /* Address of homa_recvmsg_args struct. */
size_t msg_controllen; /* Must be sizeof(struct homa_recvmsg_args). */
int msg_flags; /* Not used by Homa. */
};
.EE
.vs +2
.ps +1
.in
.PP
Homa requires additional information beyond what can be represented in a
.BR "struct msghdr" ,
so the
.B msg_controllen
field must refer to a structure of the following type:
.PP
.in +4n
.ps -1
.vs -2
.EX
struct homa_recvmsg_args {
uint64_t id; /* If nonzero, specifies id of
* desired RPC, which must be
* private. */
uint64_t completion_cookie; /* Value from sendmsg for request. */
uint32_t num_bpages; /* Number of valid entries in
* bpage_offsets. */
uint32_t bpage_offsets[HOMA_MAX_BPAGES]; /* Tokens for buffer pages. */
};
.EE
.vs +2
.ps +1
.in
.PP
The
.B msghdr
and
.B homa_recvmsg_args
structs are used both for passing parameter
information into Homa and for receiving result information:
.nr step 1 1
.IP \[bu] 2
The initial value of
.B id
indicates what message(s) the caller is interested in, in one of two ways.
If the value is nonzero, it gives the RPC identifier for a specific
RPC; it must be an RPC for which the caller is client, and it must
have been specified as
.I private
when
.B sendmsg
was invoked to initate the RPC. In this case,
.B recvmsg
will wait for the response message for that RPC.
If the initial value of
.B id
is zero, then the system call will wait for any message that is not a private
response (the message could be either a request or response).
.IP \[bu]
On a successful return Homa will use the structs to return information
about the message received. The
.B id
field will be set to the RPC identifier for the received message (if
.B id
is odd it means the message is a request; even means that it is a
response). If
.IR msg ->\c
.B msg_name
is not NULL, then a
.B sockaddr_in
or
.B sockaddr_in6
will be stored at its target (depending on the address family of
.IR sockfd ),
describing the sender of the message.
For response messages, the
.BR completion_cookie
field will be set to the value specified when the corresponding request
was sent (typically this will be information that helps the application
locate its information about the RPC).
For requests, or if an error prevented an RPC from being found,
.B completion_cookie
will be zero.
.IP \[bu]
The output values of
.B num_bpages
and
.B bpage_offsets
fields will describe where Homa has stored
the message in the socket's buffer region. Messages are divided up into
one or more chunks called
.IR "bpages".
All but the last bpage for a message will have
.B HOMA_BPAGE_SIZE
bytes (which is a power of two) and will be aligned on a
.B HOMA_BPAGE_SIZE
boundary within the buffer pool.
The last bpage for a message may be smaller than
.B HOMA_BPAGE_SIZE
and is not necessarily aligned.
The number of bpages being returned
(up to
.BR HOMA_MAX_BPAGES )
is given by
.B num_bpages
and the locations of the bpages are stored in
.BR bpage_offsets .
Each entry in
.BR bpage_offsets
is an offset from the beginning of the buffer region
for the socket. Each of these bpages is now owned by the application
and must be returned to Homa in a future
.BR recvmsg
call (see below).
.IP \[bu]
The input values of
.B num_bpages
and
.B bpage_offsets
are used to return buffer space to Homa.
Each of the
.B num_bpages
values in
.B bpage_offsets
must have been returned by some previous call to
.BR recvmsg .
The order of the bpages returned in
.B bpage_offsets
is irrelevant, and a single
.B recvmsg
call can include bpages from multiple messages; all that matters is
that each bpage is returned to Homa exactly once.
.IP \[bu]
.IR msg ->\c
.B msg_controllen
will be set to zero by the call.
.PP
.B recvmsg
normally waits until a suitable message has arrived, but nonblocking
behavior may be requested either by setting the
.BR MSG_DONTWAIT
bit in the
.BR flags
argument to
.BR recvmsg
or by setting the
.B O_NONBLOCK
flag for the socket using
.BR fcntl .
If
.B recvmsg
is invoked in nonblocking mode and no appropriate message is available,
it will fail with an
.I errno
value of
.BR EAGAIN .
.SH RETURN VALUE
The return value is the length of the message in bytes for success and
-1 if an error occurred. If
.B id
is zero after an error, it means that the failure prevented a message
from being received.
If
.B id
is nonzero, it means that a specific RPC has failed.
For request messages, this can happen after errors such as
.B EFAULT
errors (the kernel couldn't write to user space to return
the message or other metadata associated with the system call) or
.B ENOMEM
(the kernel ran out of buffer space to store the message).
For response messages,
.I errno
values such as
.BR ENOTCONN ,
.BR EHOSTUNREACH ,
or
.B ETIMEDOUT
can occur if there was no server at the specified address, it couldn't
be reached, or it timed out, respectively.
.B ENOMEM
can also occur for responses. If
.B id
is nonzero and even (i.e. the message that failed was a response) then the
.B completion_cookie
field will also be set.
.PP
After sucessfully receiving a message, an application has two responsibilities.
First, it must eventually return the message's bpages to Homa as described
above. Second, if
the message is a request, the application must eventually send a response
(Homa retains state for each request until its response has been sent; if
no responses are sent, kernel state will accumulate and the socket may
eventually block).
.PP
In an error return
.B num_bpages
is normally 0 (no RPC is being returned, so there are no bpages to worry
about). However, if
.B num_pages
is nonzero when
.B recvmsg
is invoked (i.e., the application is returning buffer space to Homa)
and an error prevents Homa from freeing those bpages, then on return
.B num_pages
and
.B bpage_offsets
will have the same values that were passed into
.BR recvmsg .
This indicates that the bpages still belong to the application. If they
are not passed back to Homa in a future
.B recvmsg
call, Homa will not be able to reuse their memory space.
.SH ERRORS
.PP
When
.B recvmsg
returns an error,
.I errno
will have one of the following values:
.TP
.B EAGAIN
No appropriate message was available and the operation was nonblocking.
.TP
.B EAFNOSUPPORT
The address family specified by
.I dest_addr
does not match the address family specified when the socket was opened
.RB ( AF_INET
or
.BR AF_INET6 ).
.TP
.B EBADF
.I sockfd
is not a valid open file descriptor.
.TP
.B EFAULT
An invalid user space address was specified for an argument.
.TP
.B EINTR
A signal occurred before a message was received; see
.BR signal (7).
.TP
.B EHOSTUNREACH
No route could be found to the destination host.
.TP
.B EINVAL
The size of the request exceeded
.BR HOMA_MAX_MESSAGE_LENGTH ,
or
.I sockfd
was not a Homa socket.
.TP
.B ENOMEM
Memory could not be allocated for internal data structures needed
for the message, or space in the application-supplied buffer pool
was exhausted.
.TP
.B ENOTCONN
There was no server connected to the port specified when the request
was sent.
.TP
.B ESHUTDOWN
The socked has been disabled using
.BR shutdown (2).
.SH SEE ALSO
.BR sendmsg (2),
.BR homa (7)