diff options
| author | Diego Nehab <diego.nehab@gmail.com> | 2012-07-31 22:02:10 -0700 |
|---|---|---|
| committer | Diego Nehab <diego.nehab@gmail.com> | 2012-07-31 22:02:10 -0700 |
| commit | 5616f3a0aec74b93814b4d4f6b8271a9cfbdd678 (patch) | |
| tree | f3ba9e4096426dfb0c2769f2860ce396b2169340 /src | |
| parent | c1bb432effa502d055c23857a12e93a4bbc780d1 (diff) | |
| parent | d777341eafe019dcd6da0547b82cf24abfb34594 (diff) | |
| download | luasocket-5616f3a0aec74b93814b4d4f6b8271a9cfbdd678.tar.gz luasocket-5616f3a0aec74b93814b4d4f6b8271a9cfbdd678.tar.bz2 luasocket-5616f3a0aec74b93814b4d4f6b8271a9cfbdd678.zip | |
Merge pull request #15 from darkrain42/unstable
tcp: Initialize clnt->family in :accept()
Diffstat (limited to 'src')
| -rw-r--r-- | src/tcp.c | 6 |
1 files changed, 5 insertions, 1 deletions
| @@ -192,12 +192,14 @@ static int meth_accept(lua_State *L) | |||
| 192 | p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 192 | p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
| 193 | auxiliar_setclass(L, "tcp{client}", -1); | 193 | auxiliar_setclass(L, "tcp{client}", -1); |
| 194 | /* initialize structure fields */ | 194 | /* initialize structure fields */ |
| 195 | memset(clnt, 0, sizeof(t_tcp)); | ||
| 195 | socket_setnonblocking(&sock); | 196 | socket_setnonblocking(&sock); |
| 196 | clnt->sock = sock; | 197 | clnt->sock = sock; |
| 197 | io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv, | 198 | io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv, |
| 198 | (p_error) socket_ioerror, &clnt->sock); | 199 | (p_error) socket_ioerror, &clnt->sock); |
| 199 | timeout_init(&clnt->tm, -1, -1); | 200 | timeout_init(&clnt->tm, -1, -1); |
| 200 | buffer_init(&clnt->buf, &clnt->io, &clnt->tm); | 201 | buffer_init(&clnt->buf, &clnt->io, &clnt->tm); |
| 202 | clnt->family = server->family; | ||
| 201 | return 1; | 203 | return 1; |
| 202 | } else { | 204 | } else { |
| 203 | lua_pushnil(L); | 205 | lua_pushnil(L); |
| @@ -354,6 +356,7 @@ static int tcp_create(lua_State *L, int family) { | |||
| 354 | if (!err) { | 356 | if (!err) { |
| 355 | /* allocate tcp object */ | 357 | /* allocate tcp object */ |
| 356 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 358 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
| 359 | memset(tcp, 0, sizeof(t_tcp)); | ||
| 357 | /* set its type as master object */ | 360 | /* set its type as master object */ |
| 358 | auxiliar_setclass(L, "tcp{master}", -1); | 361 | auxiliar_setclass(L, "tcp{master}", -1); |
| 359 | /* initialize remaining structure fields */ | 362 | /* initialize remaining structure fields */ |
| @@ -368,7 +371,7 @@ static int tcp_create(lua_State *L, int family) { | |||
| 368 | (p_error) socket_ioerror, &tcp->sock); | 371 | (p_error) socket_ioerror, &tcp->sock); |
| 369 | timeout_init(&tcp->tm, -1, -1); | 372 | timeout_init(&tcp->tm, -1, -1); |
| 370 | buffer_init(&tcp->buf, &tcp->io, &tcp->tm); | 373 | buffer_init(&tcp->buf, &tcp->io, &tcp->tm); |
| 371 | tcp->family = family; | 374 | tcp->family = family; |
| 372 | return 1; | 375 | return 1; |
| 373 | } else { | 376 | } else { |
| 374 | lua_pushnil(L); | 377 | lua_pushnil(L); |
| @@ -435,6 +438,7 @@ static int global_connect(lua_State *L) { | |||
| 435 | struct addrinfo bindhints, connecthints; | 438 | struct addrinfo bindhints, connecthints; |
| 436 | const char *err = NULL; | 439 | const char *err = NULL; |
| 437 | /* initialize tcp structure */ | 440 | /* initialize tcp structure */ |
| 441 | memset(tcp, 0, sizeof(t_tcp)); | ||
| 438 | io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv, | 442 | io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv, |
| 439 | (p_error) socket_ioerror, &tcp->sock); | 443 | (p_error) socket_ioerror, &tcp->sock); |
| 440 | timeout_init(&tcp->tm, -1, -1); | 444 | timeout_init(&tcp->tm, -1, -1); |
