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