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_read</title>
17
18</head>
19<body>
20
21<h1 align="center">mtcp_read</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_read
41&minus; read bytestream from an mTCP 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_read(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>);</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_read</b>()
63can be used to read up to <i>len</i> number of bytes from
64mTCP socket via socket descriptor <i>sockid</i> into the
65buffer starting at <i>buf.</i> It is the responsibility of
66the user to allocate memory for <i>buf</i> array.</p>
67
68<p style="margin-left:11%; margin-top: 1em">For cases when
69the total number of buffered unread bytes in the socket are
70less than <i>len,</i> <b>mtcp_read()</b> copies entire data
71to <i>buf</i> and returns the actual number of bytes that
72can be used by the application.</p>
73
74<p style="margin-left:11%; margin-top: 1em">An
75<b>mtcp_read</b>() call takes an additional argument named
76<i>mctx</i> that represents the per-core mTCP context in an
77application (see <b>mtcp_create_context()</b> for
78details).</p>
79
80<h2>RETURN VALUE
81<a name="RETURN VALUE"></a>
82</h2>
83
84
85<p style="margin-left:11%; margin-top: 1em">On success, the
86number of bytes read is returned. It is not an error if this
87number is smaller than the number of bytes requested; this
88may happen when the socket has fewer number of bytes
89buffered at that moment. On all errors, -1 is returned and
90<i>errno</i> is set appropriately.</p>
91
92<h2>ERRORS
93<a name="ERRORS"></a>
94</h2>
95
96
97<table width="100%" border="0" rules="none" frame="void"
98       cellspacing="0" cellpadding="0">
99<tr valign="top" align="left">
100<td width="11%"></td>
101<td width="12%">
102
103
104<p style="margin-top: 1em"><b>EBADF</b></p></td>
105<td width="3%"></td>
106<td width="74%">
107
108
109<p style="margin-top: 1em">The socket descriptor
110<i>sockid</i> is invalid.</p></td></tr>
111<tr valign="top" align="left">
112<td width="11%"></td>
113<td width="12%">
114
115
116<p><b>ENOTSOCK</b></p></td>
117<td width="3%"></td>
118<td width="74%">
119
120
121<p>The socket referred to by <i>sockid</i> has invalid
122<i>type</i></p> </td></tr>
123<tr valign="top" align="left">
124<td width="11%"></td>
125<td width="12%">
126
127
128<p><b>ENOTCONN</b></p></td>
129<td width="3%"></td>
130<td width="74%">
131
132
133<p>Th socket referred to by <i>sockid</i> is in a TCP state
134that disallows read operations.</p></td></tr>
135<tr valign="top" align="left">
136<td width="11%"></td>
137<td width="12%">
138
139
140<p><b>EAGAIN</b></p></td>
141<td width="3%"></td>
142<td width="74%">
143
144
145<p>The socket referred to by <i>sockid</i> does not have
146any available bytes in its buffer for reading.</p></td></tr>
147</table>
148
149<h2>AUTHORS
150<a name="AUTHORS"></a>
151</h2>
152
153
154<p style="margin-left:11%; margin-top: 1em">mOS development
155team &lt;[email protected]&gt;</p>
156
157<h2>SEE ALSO
158<a name="SEE ALSO"></a>
159</h2>
160
161
162
163<p style="margin-left:11%; margin-top: 1em"><b>mtcp_bind</b>(),
164<b>mtcp_listen</b>(), <b>mtcp_accept</b>(),
165<b>mtcp_connect</b>(), <b>mtcp_socket</b>(),
166<b>mtcp_write</b>()</p>
167
168<h2>COLOPHON
169<a name="COLOPHON"></a>
170</h2>
171
172
173<p style="margin-left:11%; margin-top: 1em">This page is
174part of mOS release 0.3 <i>docs</i> section. A description
175of the project, and information about reporting bugs, can be
176found at http://mos.kaist.edu/.</p>
177<hr>
178</body>
179</html>
180