1<!-- Creator     : groff version 1.22.2 -->
2<!-- CreationDate: Wed Feb  1 23:55:12 2017 -->
3<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
4"http://www.w3.org/TR/html4/loose.dtd">
5<html>
6<head>
7<meta name="generator" content="groff -Thtml, see www.gnu.org">
8<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
9<meta name="Content-Style" content="text/css">
10<style type="text/css">
11       p       { margin-top: 0; margin-bottom: 0; vertical-align: top }
12       pre     { margin-top: 0; margin-bottom: 0; vertical-align: top }
13       table   { margin-top: 0; margin-bottom: 0; vertical-align: top }
14       h1      { text-align: center }
15</style>
16<title>mtcp_recv</title>
17
18</head>
19<body>
20
21<h1 align="center">mtcp_recv</h1>
22
23<a href="#NAME">NAME</a><br>
24<a href="#SYNOPSIS">SYNOPSIS</a><br>
25<a href="#DESCRIPTION">DESCRIPTION</a><br>
26<a href="#RETURN VALUE">RETURN VALUE</a><br>
27<a href="#ERRORS">ERRORS</a><br>
28<a href="#AUTHORS">AUTHORS</a><br>
29<a href="#SEE ALSO">SEE ALSO</a><br>
30<a href="#COLOPHON">COLOPHON</a><br>
31
32<hr>
33
34
35<h2>NAME
36<a name="NAME"></a>
37</h2>
38
39
40<p style="margin-left:11%; margin-top: 1em">mtcp_recv
41&minus; receive a message from a socket</p>
42
43<h2>SYNOPSIS
44<a name="SYNOPSIS"></a>
45</h2>
46
47
48<p style="margin-left:11%; margin-top: 1em"><b>#include
49&lt;mtcp_api.h&gt;</b></p>
50
51<p style="margin-left:11%; margin-top: 1em"><b>ssize_t
52mtcp_recv(mctx_t</b> <i>mctx</i><b>, int</b>
53<i>sockid</i><b>, char *</b><i>buf</i><b>, size_t</b>
54<i>len</i><b>, int</b> <i>flags</i><b>);</b></p>
55
56<h2>DESCRIPTION
57<a name="DESCRIPTION"></a>
58</h2>
59
60
61
62<p style="margin-left:11%; margin-top: 1em"><b>mtcp_recv</b>()
63call is normally used only on a <i>connected</i> socket (see
64<b>mtcp_connect()</b>) and is identical to
65<b>mtcp_read()</b> with <i>flags</i> value set to 0. The
66function can be used to read up to <i>len</i> number of
67bytes from mTCP socket via socket descriptor <i>sockid</i>
68into the buffer starting at <i>buf.</i> It is the
69responsibility of the user to allocate memory for <i>buf</i>
70array.</p>
71
72<p style="margin-left:11%; margin-top: 1em">For cases when
73the total number of buffered unread bytes in the socket are
74less than <i>len,</i> <b>mtcp_recv()</b> copies entire data
75to <i>buf</i> and returns the actual number of bytes that
76can be used by the application.</p>
77
78<p style="margin-left:11%; margin-top: 1em">An
79<b>mtcp_recv</b>() call takes an additional argument named
80<i>mctx</i> that represents the per-core mTCP context in an
81application (see <b>mtcp_create_context()</b> for
82details).</p>
83
84<p style="margin-left:11%; margin-top: 1em">The
85<i>flags</i> argument to a <b>mtcp_recv()</b> call currently
86accepts only one non-zero value:</p>
87
88<table width="100%" border="0" rules="none" frame="void"
89       cellspacing="0" cellpadding="0">
90<tr valign="top" align="left">
91<td width="11%"></td>
92<td width="12%">
93
94
95<p><b>MSG_PEEK</b></p></td>
96<td width="3%"></td>
97<td width="74%">
98
99
100<p>This flag causes the receive operation to return data
101from the beginning of the receive queue without removing
102that data from the queue. Thus, a subsequent receive call
103will return the same data.</p></td></tr>
104</table>
105
106<h2>RETURN VALUE
107<a name="RETURN VALUE"></a>
108</h2>
109
110
111<p style="margin-left:11%; margin-top: 1em">On success, the
112number of bytes read is returned. It is not an error if this
113number is smaller than the number of bytes requested; this
114may happen when the socket has fewer number of bytes
115buffered at that moment. On all errors, -1 is returned and
116<i>errno</i> is set appropriately.</p>
117
118<h2>ERRORS
119<a name="ERRORS"></a>
120</h2>
121
122
123<table width="100%" border="0" rules="none" frame="void"
124       cellspacing="0" cellpadding="0">
125<tr valign="top" align="left">
126<td width="11%"></td>
127<td width="12%">
128
129
130<p style="margin-top: 1em"><b>EBADF</b></p></td>
131<td width="3%"></td>
132<td width="74%">
133
134
135<p style="margin-top: 1em">The socket descriptor
136<i>sockid</i> is invalid.</p></td></tr>
137<tr valign="top" align="left">
138<td width="11%"></td>
139<td width="12%">
140
141
142<p><b>EINVAL</b></p></td>
143<td width="3%"></td>
144<td width="74%">
145
146
147<p>Invalid argument passed.</p></td></tr>
148<tr valign="top" align="left">
149<td width="11%"></td>
150<td width="12%">
151
152
153<p><b>ENOTSOCK</b></p></td>
154<td width="3%"></td>
155<td width="74%">
156
157
158<p>The socket referred to by <i>sockid</i> has invalid
159<i>type</i></p> </td></tr>
160<tr valign="top" align="left">
161<td width="11%"></td>
162<td width="12%">
163
164
165<p><b>ENOTCONN</b></p></td>
166<td width="3%"></td>
167<td width="74%">
168
169
170<p>Th socket referred to by <i>sockid</i> is in a TCP state
171that disallows read operations.</p></td></tr>
172<tr valign="top" align="left">
173<td width="11%"></td>
174<td width="12%">
175
176
177<p><b>EAGAIN</b></p></td>
178<td width="3%"></td>
179<td width="74%">
180
181
182<p>The socket referred to by <i>sockid</i> does not have
183any available bytes in its buffer for reading.</p></td></tr>
184</table>
185
186<h2>AUTHORS
187<a name="AUTHORS"></a>
188</h2>
189
190
191<p style="margin-left:11%; margin-top: 1em">mOS development
192team &lt;[email protected]&gt;</p>
193
194<h2>SEE ALSO
195<a name="SEE ALSO"></a>
196</h2>
197
198
199
200<p style="margin-left:11%; margin-top: 1em"><b>mtcp_bind</b>(),
201<b>mtcp_read</b>(), <b>mtcp_accept</b>(),
202<b>mtcp_connect</b>(), <b>mtcp_socket</b>(),
203<b>mtcp_write</b>()</p>
204
205<h2>COLOPHON
206<a name="COLOPHON"></a>
207</h2>
208
209
210<p style="margin-left:11%; margin-top: 1em">This page is
211part of mOS release 0.3 <i>docs</i> section. A description
212of the project, and information about reporting bugs, can be
213found at http://mos.kaist.edu/.</p>
214<hr>
215</body>
216</html>
217