MCPcopy Create free account
hub / github.com/Tencent/UnLua / meth_accept

Function meth_accept

Plugins/UnLuaExtensions/LuaSocket/Source/src/tcp.cpp:212–237  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Waits for and returns a client object attempting connection to the * server object \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

210* server object
211\*-------------------------------------------------------------------------*/
212static int meth_accept(lua_State *L)
213{
214 p_tcp server = (p_tcp) auxiliar_checkclass(L, "tcp{server}", 1);
215 p_timeout tm = timeout_markstart(&server->tm);
216 t_socket sock;
217 const char *err = inet_tryaccept(&server->sock, server->family, &sock, tm);
218 /* if successful, push client socket */
219 if (err == NULL) {
220 p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
221 auxiliar_setclass(L, "tcp{client}", -1);
222 /* initialize structure fields */
223 memset(clnt, 0, sizeof(t_tcp));
224 socket_setnonblocking(&sock);
225 clnt->sock = sock;
226 io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv,
227 (p_error) socket_ioerror, &clnt->sock);
228 timeout_init(&clnt->tm, -1, -1);
229 buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
230 clnt->family = server->family;
231 return 1;
232 } else {
233 lua_pushnil(L);
234 lua_pushstring(L, err);
235 return 2;
236 }
237}
238
239/*-------------------------------------------------------------------------*\
240* Binds an object to an address

Callers

nothing calls this directly

Calls 10

auxiliar_checkclassFunction · 0.85
timeout_markstartFunction · 0.85
inet_tryacceptFunction · 0.85
auxiliar_setclassFunction · 0.85
io_initFunction · 0.85
timeout_initFunction · 0.85
buffer_initFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
socket_setnonblockingFunction · 0.70

Tested by

no test coverage detected