diff options
Diffstat (limited to 'src/tcp.c')
-rw-r--r-- | src/tcp.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -130,7 +130,7 @@ static int meth_setoption(lua_State *L) | |||
130 | static int meth_getfd(lua_State *L) | 130 | static int meth_getfd(lua_State *L) |
131 | { | 131 | { |
132 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); | 132 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); |
133 | lua_pushnumber(L, tcp->sock); | 133 | lua_pushnumber(L, (int) tcp->sock); |
134 | return 1; | 134 | return 1; |
135 | } | 135 | } |
136 | 136 | ||
@@ -164,6 +164,7 @@ static int meth_accept(lua_State *L) | |||
164 | p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp)); | 164 | p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp)); |
165 | aux_setclass(L, "tcp{client}", -1); | 165 | aux_setclass(L, "tcp{client}", -1); |
166 | /* initialize structure fields */ | 166 | /* initialize structure fields */ |
167 | sock_setnonblocking(&sock); | ||
167 | clnt->sock = sock; | 168 | clnt->sock = sock; |
168 | io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, &clnt->sock); | 169 | io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, &clnt->sock); |
169 | tm_init(&clnt->tm, -1, -1); | 170 | tm_init(&clnt->tm, -1, -1); |
@@ -310,10 +311,11 @@ static int global_create(lua_State *L) | |||
310 | if (!err) { | 311 | if (!err) { |
311 | /* allocate tcp object */ | 312 | /* allocate tcp object */ |
312 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 313 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
313 | tcp->sock = sock; | ||
314 | /* set its type as master object */ | 314 | /* set its type as master object */ |
315 | aux_setclass(L, "tcp{master}", -1); | 315 | aux_setclass(L, "tcp{master}", -1); |
316 | /* initialize remaining structure fields */ | 316 | /* initialize remaining structure fields */ |
317 | sock_setnonblocking(&sock); | ||
318 | tcp->sock = sock; | ||
317 | io_init(&tcp->io, (p_send) sock_send, (p_recv) sock_recv, &tcp->sock); | 319 | io_init(&tcp->io, (p_send) sock_send, (p_recv) sock_recv, &tcp->sock); |
318 | tm_init(&tcp->tm, -1, -1); | 320 | tm_init(&tcp->tm, -1, -1); |
319 | buf_init(&tcp->buf, &tcp->io, &tcp->tm); | 321 | buf_init(&tcp->buf, &tcp->io, &tcp->tm); |