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