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