-------------------------------------------------------------------------*\ * Waits for and returns a client object attempting connection to the * server object \*-------------------------------------------------------------------------*/
| 210 | * server object |
| 211 | \*-------------------------------------------------------------------------*/ |
| 212 | static 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 |
nothing calls this directly
no test coverage detected