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_accept</title> 17<link rel="stylesheet" href="./common.css"> 18</head> 19<body> 20<div class="main"> 21<h1 align="center">mtcp_accept</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="#NOTES">NOTES</a><br> 29<a href="#AUTHORS">AUTHORS</a><br> 30<a href="#SEE ALSO">SEE ALSO</a><br> 31<a href="#COLOPHON">COLOPHON</a><br> 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_accept 41− accept a connection on 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<mtcp_api.h></b></p> 50 51<p style="margin-left:11%; margin-top: 1em"><b>int 52mtcp_accept(mctx_t</b> <i>mctx</i><b>, int</b> 53<i>sockid</i><b>, struct sockaddr *</b><i>addr</i><b>, 54socklen_t *</b><i>addrlen</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_accept</b>() 63function is used to accept an incoming connection request 64from a TCP client. During a successful <b>mtcp_accept()</b> 65call, the mTCP stack extracts the first connection request 66from the listening queue of pending connections associated 67with the passive socket ID <i>sockid.</i> It then creates a 68new socket and returns its corresponding socket ID to the 69user. The newly created socket (that is returned) can be 70used to communicate with the TCP client while the original 71socket <i>sockid</i> is unaffected by this call. The passive 72socket represented by the <i>sockid</i> socket descriptor 73should be bound to a local address using <b>mtcp_bind()</b> 74function and should be listening for connections by calling 75<b>mtcp_listen()</b> function before it can be used for 76accepting new connection requests.</p> 77 78<p style="margin-left:11%; margin-top: 1em">The <i>addr</i> 79argument is a pointer to <i>sockaddr</i> structure that gets 80filled up with the address of the peer node while the 81<i>addrlen</i> field contains the size of the peer address. 82If the <i>addr</i> argument is NULL, nothing is filled in 83and as a result, <i>addrlen</i> is not used and should also 84be NULL.</p> 85 86<p style="margin-left:11%; margin-top: 1em">If no pending 87connections are present on the queue, mtcp_accept() fails 88with error <b>EAGAIN</b> errno.</p> 89 90<p style="margin-left:11%; margin-top: 1em">In order to be 91notified of incoming connections on a socket, the user can 92use <b>mtcp_epoll_wait()</b> function call. A readable event 93is delivered when a new connection arrives on the listening 94socket.</p> 95 96<p style="margin-left:11%; margin-top: 1em">An 97<b>mtcp_accept</b>() call takes an additional argument named 98<i>mctx</i> that represents the per-core mTCP context in an 99application (see <b>mtcp_create_context()</b> for 100details).</p> 101 102<h2>RETURN VALUE 103<a name="RETURN VALUE"></a> 104</h2> 105 106 107<p style="margin-left:11%; margin-top: 1em">Returns an mTCP 108descriptor ID of the newly created active mTCP socket; -1 on 109failure. In case of failure, <i>errno</i> is set 110appropriately.</p> 111 112<h2>ERRORS 113<a name="ERRORS"></a> 114</h2> 115 116 117<table width="100%" border="0" rules="none" frame="void" 118 cellspacing="0" cellpadding="0"> 119<tr valign="top" align="left"> 120<td width="11%"></td> 121<td width="9%"> 122 123 124<p style="margin-top: 1em"><b>EAGAIN</b></p></td> 125<td width="6%"></td> 126<td width="74%"> 127 128 129<p style="margin-top: 1em">No connections requests are 130available at the moment.</p></td></tr> 131<tr valign="top" align="left"> 132<td width="11%"></td> 133<td width="9%"> 134 135 136<p><b>EBADF</b></p></td> 137<td width="6%"></td> 138<td width="74%"> 139 140 141<p><i>sockid</i> is not a valid socket descriptor for 142accepting connections.</p></td></tr> 143<tr valign="top" align="left"> 144<td width="11%"></td> 145<td width="9%"> 146 147 148<p><b>EINTR</b></p></td> 149<td width="6%"></td> 150<td width="74%"> 151 152 153<p>The application thread is scheduled to shut down.</p></td></tr> 154<tr valign="top" align="left"> 155<td width="11%"></td> 156<td width="9%"> 157 158 159<p><b>EINVAL</b></p></td> 160<td width="6%"></td> 161<td width="74%"> 162 163 164<p>The socket referred to by the <i>sockid</i> argument is 165not a listening (passive) socket.</p></td></tr> 166<tr valign="top" align="left"> 167<td width="11%"></td> 168<td width="9%"> 169 170 171<p><b>ENFILE</b></p></td> 172<td width="6%"></td> 173<td width="74%"> 174 175 176<p>New active socket could not be created as the mTCP core 177is out of socket descriptors at the moment.</p></td></tr> 178</table> 179 180<h2>NOTES 181<a name="NOTES"></a> 182</h2> 183 184 185<p style="margin-left:11%; margin-top: 1em">For performance 186reasons, it is recommended that the <i>same</i> thread 187(represented by <i>mctx</i> argument) that spawns the active 188socket via <b>mtcp_accept()</b> should handle operations 189<b>(mtcp_read(), mtcp_write(),</b> and 190<b>mtcp_getsockopt())</b> on that socket for the entire 191lifetime of the connection (till <b>mtcp_close()).</b></p> 192 193<h2>AUTHORS 194<a name="AUTHORS"></a> 195</h2> 196 197 198<p style="margin-left:11%; margin-top: 1em">mOS 199development team <[email protected]></p> 200 201<h2>SEE ALSO 202<a name="SEE ALSO"></a> 203</h2> 204 205 206 207<p style="margin-left:11%; margin-top: 1em"><b>mtcp_bind</b>(), 208<b>mtcp_listen</b>(), <b>mtcp_socket</b>(), 209<b>mtcp_connect</b>(), <b>mtcp_read</b>(), 210<b>mtcp_write</b>()</p> 211 212<h2>COLOPHON 213<a name="COLOPHON"></a> 214</h2> 215 216 217<p style="margin-left:11%; margin-top: 1em">This page is 218part of mOS release 0.3 <i>docs</i> section. A description 219of the project, and information about reporting bugs, can be 220found at http://mos.kaist.edu/.</p> 221<!-- <hr> --> 222<br> 223<div class="footer"> 224 <img src="back-arrow.jpg" width="2%" height="2%"><a href="http://mos.kaist.edu/index_man.html">Back to Index</a> 225</div> 226</div> 227</body> 228</html> 229