diff options
Diffstat (limited to 'src/tcp.c')
-rw-r--r-- | src/tcp.c | 33 |
1 files changed, 18 insertions, 15 deletions
@@ -39,25 +39,26 @@ static int meth_dirty(lua_State *L); | |||
39 | 39 | ||
40 | /* tcp object methods */ | 40 | /* tcp object methods */ |
41 | static luaL_reg tcp[] = { | 41 | static luaL_reg tcp[] = { |
42 | {"connect", meth_connect}, | 42 | {"__gc", meth_close}, |
43 | {"send", meth_send}, | 43 | {"accept", meth_accept}, |
44 | {"receive", meth_receive}, | ||
45 | {"bind", meth_bind}, | 44 | {"bind", meth_bind}, |
45 | {"close", meth_close}, | ||
46 | {"connect", meth_connect}, | ||
47 | {"dirty", meth_dirty}, | ||
48 | {"getfd", meth_getfd}, | ||
49 | {"getpeername", meth_getpeername}, | ||
50 | {"getsockname", meth_getsockname}, | ||
46 | {"listen", meth_listen}, | 51 | {"listen", meth_listen}, |
47 | {"accept", meth_accept}, | 52 | {"receive", meth_receive}, |
53 | {"send", meth_send}, | ||
54 | {"setfd", meth_setfd}, | ||
55 | {"setoption", meth_setoption}, | ||
48 | {"setpeername", meth_connect}, | 56 | {"setpeername", meth_connect}, |
49 | {"setsockname", meth_bind}, | 57 | {"setsockname", meth_bind}, |
50 | {"getpeername", meth_getpeername}, | ||
51 | {"getsockname", meth_getsockname}, | ||
52 | {"settimeout", meth_settimeout}, | 58 | {"settimeout", meth_settimeout}, |
53 | {"close", meth_close}, | ||
54 | {"shutdown", meth_shutdown}, | 59 | {"shutdown", meth_shutdown}, |
55 | {"setoption", meth_setoption}, | ||
56 | {"__gc", meth_close}, | ||
57 | {"getfd", meth_getfd}, | ||
58 | {"setfd", meth_setfd}, | ||
59 | {"dirty", meth_dirty}, | ||
60 | {NULL, NULL} | 60 | {NULL, NULL} |
61 | |||
61 | }; | 62 | }; |
62 | 63 | ||
63 | /* socket option handlers */ | 64 | /* socket option handlers */ |
@@ -78,7 +79,7 @@ static luaL_reg func[] = { | |||
78 | /*-------------------------------------------------------------------------*\ | 79 | /*-------------------------------------------------------------------------*\ |
79 | * Initializes module | 80 | * Initializes module |
80 | \*-------------------------------------------------------------------------*/ | 81 | \*-------------------------------------------------------------------------*/ |
81 | void tcp_open(lua_State *L) | 82 | int tcp_open(lua_State *L) |
82 | { | 83 | { |
83 | /* create classes */ | 84 | /* create classes */ |
84 | aux_newclass(L, "tcp{master}", tcp); | 85 | aux_newclass(L, "tcp{master}", tcp); |
@@ -96,6 +97,7 @@ void tcp_open(lua_State *L) | |||
96 | /* define library functions */ | 97 | /* define library functions */ |
97 | luaL_openlib(L, LUASOCKET_LIBNAME, func, 0); | 98 | luaL_openlib(L, LUASOCKET_LIBNAME, func, 0); |
98 | lua_pop(L, 1); | 99 | lua_pop(L, 1); |
100 | return 0; | ||
99 | } | 101 | } |
100 | 102 | ||
101 | /*=========================================================================*\ | 103 | /*=========================================================================*\ |
@@ -250,7 +252,7 @@ static int meth_listen(lua_State *L) | |||
250 | \*-------------------------------------------------------------------------*/ | 252 | \*-------------------------------------------------------------------------*/ |
251 | static int meth_shutdown(lua_State *L) | 253 | static int meth_shutdown(lua_State *L) |
252 | { | 254 | { |
253 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); | 255 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{client}", 1); |
254 | const char *how = luaL_optstring(L, 2, "both"); | 256 | const char *how = luaL_optstring(L, 2, "both"); |
255 | switch (how[0]) { | 257 | switch (how[0]) { |
256 | case 'b': | 258 | case 'b': |
@@ -266,7 +268,8 @@ static int meth_shutdown(lua_State *L) | |||
266 | sock_shutdown(&tcp->sock, 0); | 268 | sock_shutdown(&tcp->sock, 0); |
267 | break; | 269 | break; |
268 | } | 270 | } |
269 | return 0; | 271 | lua_pushnumber(L, 1); |
272 | return 1; | ||
270 | error: | 273 | error: |
271 | luaL_argerror(L, 2, "invalid shutdown method"); | 274 | luaL_argerror(L, 2, "invalid shutdown method"); |
272 | return 0; | 275 | return 0; |