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

Function meth_accept

Plugins/UnLuaExtensions/LuaSocket/Source/src/unixstream.cpp:158–180  ·  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

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

Callers

nothing calls this directly

Calls 11

auxiliar_checkclassFunction · 0.85
timeout_markstartFunction · 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