MCPcopy Create free account
hub / github.com/defold/defold / meth_accept

Function meth_accept

engine/script/src/luasocket/unix.c:164–186  ·  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

162* server object
163\*-------------------------------------------------------------------------*/
164static int meth_accept(lua_State *L) {
165 p_unix server = (p_unix) auxiliar_checkclass(L, "unix{server}", 1);
166 p_timeout tm = timeout_markstart(&server->tm);
167 t_socket sock;
168 int err = socket_accept(&server->sock, &sock, NULL, NULL, tm);
169 /* if successful, push client socket */
170 if (err == IO_DONE) {
171 p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix));
172 auxiliar_setclass(L, "unix{client}", -1);
173 /* initialize structure fields */
174 socket_setnonblocking(&sock);
175 clnt->sock = sock;
176 io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv,
177 (p_error) socket_ioerror, &clnt->sock);
178 timeout_init(&clnt->tm, -1, -1);
179 buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
180 return 1;
181 } else {
182 lua_pushnil(L);
183 lua_pushstring(L, socket_strerror(err));
184 return 2;
185 }
186}
187
188/*-------------------------------------------------------------------------*\
189* Binds an object to an address

Callers

nothing calls this directly

Calls 12

auxiliar_checkclassFunction · 0.85
timeout_markstartFunction · 0.85
lua_newuserdataFunction · 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_acceptFunction · 0.70
socket_setnonblockingFunction · 0.70
socket_strerrorFunction · 0.70

Tested by

no test coverage detected