1<!-- Creator : groff version 1.22.2 --> 2<!-- CreationDate: Fri Feb 3 15:37:41 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_ppeek</title> 17 18</head> 19<body> 20 21<h1 align="center">mtcp_ppeek</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_ppeek 41− Peek into the bytestream from a monitoring socket 42from a given offset</p> 43 44<h2>SYNOPSIS 45<a name="SYNOPSIS"></a> 46</h2> 47 48 49<p style="margin-left:11%; margin-top: 1em"><b>#include 50<mos_api.h></b></p> 51 52<p style="margin-left:11%; margin-top: 1em"><b>ssize_t 53mtcp_ppeek(mctx_t</b> <i>mctx</i><b>, int</b> 54<i>sockid</i><b>, int</b> <i>side</i><b>, char 55*</b><i>buf</i><b>, size_t</b> <i>len</i><b>, uint64_t</b> 56<i>off</i><b>);</b></p> 57 58<h2>DESCRIPTION 59<a name="DESCRIPTION"></a> 60</h2> 61 62 63 64<p style="margin-left:11%; margin-top: 1em"><b>mtcp_ppeek</b>() 65can be used to peek up to <i>len</i> number of bytes from a 66monitoring socket via socket descriptor <i>sockid</i> into 67the buffer starting at <i>buf. from off ;</i> value which is 68the offset distance (in bytes) from the TCP initial sequence 69number. It is the responsibility of the user to allocate 70memory for <i>buf</i> array.</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_ppeek()</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">Note that the 79<i>off</i> can also point to the data in the fragmented 80buffer list of the TCP ring buffer (see 81<b>mtcp_getsockopt()).</b> If there is no received byte at 82<i>off</i> in the TCP ring buffer, it returns error. If 83there are received bytes starting from <i>off ,</i> len is 84set to be the number of bytes read from the buffer. After 85<b>mtcp_ppeek(),</b> the data in the TCP ring buffer will 86not be flushed, and the monitor offset used by 87<b>mtcp_peek()</b> is not changed.</p> 88 89<p style="margin-left:11%; margin-top: 1em">An 90<b>mtcp_ppeek</b>() call takes two additional argument named 91<i>mctx ,</i> that represents the per-core mTCP context in 92an application (see <b>mtcp_create_context()</b> for 93details); and <i>side</i> that informs the stack whether it 94needs to peek the client (MOS_SIDE_CLI) or server 95(MOS_SIDE_SVR) side.</p> 96 97<h2>RETURN VALUE 98<a name="RETURN VALUE"></a> 99</h2> 100 101 102<p style="margin-left:11%; margin-top: 1em">On success, the 103number of bytes read is returned. It is not an error if this 104number is smaller than the number of bytes requested; this 105may happen when the socket has fewer number of bytes 106buffered at that moment. On all errors, -1 is returned and 107<i>errno</i> is set appropriately.</p> 108 109<h2>ERRORS 110<a name="ERRORS"></a> 111</h2> 112 113 114<table width="100%" border="0" rules="none" frame="void" 115 cellspacing="0" cellpadding="0"> 116<tr valign="top" align="left"> 117<td width="11%"></td> 118<td width="23%"> 119 120 121<p style="margin-top: 1em"><b>EACCES</b></p></td> 122<td width="4%"></td> 123<td width="62%"> 124 125 126<p style="margin-top: 1em">The <i>mctx</i> argument is 127invalid.</p> </td></tr> 128<tr valign="top" align="left"> 129<td width="11%"></td> 130<td width="23%"> 131 132 133<p><b>EBADF</b></p></td> 134<td width="4%"></td> 135<td width="62%"> 136 137 138<p>The socket descriptor <i>sockid</i> is invalid.</p></td></tr> 139<tr valign="top" align="left"> 140<td width="11%"></td> 141<td width="23%"> 142 143 144<p><b>EINVAL</b></p></td> 145<td width="4%"></td> 146<td width="62%"> 147 148 149<p>The buffer management of the monitoring socket with 150<i>sockid</i> was already disabled.</p></td></tr> 151<tr valign="top" align="left"> 152<td width="11%"></td> 153<td width="23%"> 154 155 156<p><b>ESOCKTNOSUPPORT</b></p></td> 157<td width="4%"></td> 158<td width="62%"> 159 160 161<p>The socket referred to by <i>sockid</i> has invalid 162<i>type</i></p> </td></tr> 163<tr valign="top" align="left"> 164<td width="11%"></td> 165<td width="23%"> 166 167 168<p><b>ENOTCONN</b></p></td> 169<td width="4%"></td> 170<td width="62%"> 171 172 173<p>Th socket referred to by <i>sockid</i> is in a TCP state 174that disallows read operations.</p></td></tr> 175<tr valign="top" align="left"> 176<td width="11%"></td> 177<td width="23%"> 178 179 180<p><b>ENODATA</b></p></td> 181<td width="4%"></td> 182<td width="62%"> 183 184 185<p>The socket referred to by <i>sockid</i> does not have 186any available bytes in its buffer for reading.</p></td></tr> 187<tr valign="top" align="left"> 188<td width="11%"></td> 189<td width="23%"> 190 191 192<p><b>EPERM</b></p></td> 193<td width="4%"></td> 194<td width="62%"> 195 196 197<p>The caller is not permitted to access this function.</p></td></tr> 198</table> 199 200<h2>AUTHORS 201<a name="AUTHORS"></a> 202</h2> 203 204 205<p style="margin-left:11%; margin-top: 1em">mOS development 206team <[email protected]></p> 207 208<h2>SEE ALSO 209<a name="SEE ALSO"></a> 210</h2> 211 212 213 214<p style="margin-left:11%; margin-top: 1em"><b>mtcp_peek</b>(), 215<b>mtcp_socket</b>(),</p> 216 217<h2>COLOPHON 218<a name="COLOPHON"></a> 219</h2> 220 221 222<p style="margin-left:11%; margin-top: 1em">This page is 223part of mOS release 0.3 <i>docs</i> section. A description 224of the project, and information about reporting bugs, can be 225found at http://mos.kaist.edu/.</p> 226<hr> 227</body> 228</html> 229