diff options
Diffstat (limited to 'src/udp.c')
-rw-r--r-- | src/udp.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -33,7 +33,8 @@ static int meth_close(lua_State *L); | |||
33 | static int meth_shutdown(lua_State *L); | 33 | static int meth_shutdown(lua_State *L); |
34 | static int meth_setoption(lua_State *L); | 34 | static int meth_setoption(lua_State *L); |
35 | static int meth_settimeout(lua_State *L); | 35 | static int meth_settimeout(lua_State *L); |
36 | static int meth_fd(lua_State *L); | 36 | static int meth_getfd(lua_State *L); |
37 | static int meth_setfd(lua_State *L); | ||
37 | static int meth_dirty(lua_State *L); | 38 | static int meth_dirty(lua_State *L); |
38 | 39 | ||
39 | /* udp object methods */ | 40 | /* udp object methods */ |
@@ -51,7 +52,8 @@ static luaL_reg udp[] = { | |||
51 | {"shutdown", meth_shutdown}, | 52 | {"shutdown", meth_shutdown}, |
52 | {"setoption", meth_setoption}, | 53 | {"setoption", meth_setoption}, |
53 | {"__gc", meth_close}, | 54 | {"__gc", meth_close}, |
54 | {"fd", meth_fd}, | 55 | {"getfd", meth_getfd}, |
56 | {"setfd", meth_setfd}, | ||
55 | {"dirty", meth_dirty}, | 57 | {"dirty", meth_dirty}, |
56 | {NULL, NULL} | 58 | {NULL, NULL} |
57 | }; | 59 | }; |
@@ -194,13 +196,21 @@ static int meth_receivefrom(lua_State *L) | |||
194 | /*-------------------------------------------------------------------------*\ | 196 | /*-------------------------------------------------------------------------*\ |
195 | * Select support methods | 197 | * Select support methods |
196 | \*-------------------------------------------------------------------------*/ | 198 | \*-------------------------------------------------------------------------*/ |
197 | static int meth_fd(lua_State *L) | 199 | static int meth_getfd(lua_State *L) |
198 | { | 200 | { |
199 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); | 201 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); |
200 | lua_pushnumber(L, udp->sock); | 202 | lua_pushnumber(L, udp->sock); |
201 | return 1; | 203 | return 1; |
202 | } | 204 | } |
203 | 205 | ||
206 | /* this is very dangerous, but can be handy for those that are brave enough */ | ||
207 | static int meth_setfd(lua_State *L) | ||
208 | { | ||
209 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); | ||
210 | udp->sock = (t_sock) luaL_checknumber(L, 2); | ||
211 | return 0; | ||
212 | } | ||
213 | |||
204 | static int meth_dirty(lua_State *L) | 214 | static int meth_dirty(lua_State *L) |
205 | { | 215 | { |
206 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); | 216 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); |
@@ -312,7 +322,7 @@ static int meth_setsockname(lua_State *L) | |||
312 | p_udp udp = (p_udp) aux_checkclass(L, "udp{unconnected}", 1); | 322 | p_udp udp = (p_udp) aux_checkclass(L, "udp{unconnected}", 1); |
313 | const char *address = luaL_checkstring(L, 2); | 323 | const char *address = luaL_checkstring(L, 2); |
314 | unsigned short port = (unsigned short) luaL_checknumber(L, 3); | 324 | unsigned short port = (unsigned short) luaL_checknumber(L, 3); |
315 | const char *err = inet_trybind(&udp->sock, address, port, -1); | 325 | const char *err = inet_trybind(&udp->sock, address, port); |
316 | if (err) { | 326 | if (err) { |
317 | lua_pushnil(L); | 327 | lua_pushnil(L); |
318 | lua_pushstring(L, err); | 328 | lua_pushstring(L, err); |