diff options
| author | moteus <mimir@newmail.ru> | 2013-05-29 14:33:27 +0400 |
|---|---|---|
| committer | moteus <mimir@newmail.ru> | 2013-05-29 14:33:27 +0400 |
| commit | 1de617e3550366076737e804f1e28891605db89c (patch) | |
| tree | 2a5db457e38cdf3de1f29df4d0217999c5cd306d /src | |
| parent | b84a5f3d08b1dc9d1003506bbca53e11264e8693 (diff) | |
| download | luasocket-1de617e3550366076737e804f1e28891605db89c.tar.gz luasocket-1de617e3550366076737e804f1e28891605db89c.tar.bz2 luasocket-1de617e3550366076737e804f1e28891605db89c.zip | |
Add. Allow get `error` option to socket.
Diffstat (limited to 'src')
| -rw-r--r-- | src/options.c | 13 | ||||
| -rw-r--r-- | src/options.h | 1 | ||||
| -rw-r--r-- | src/tcp.c | 1 | ||||
| -rw-r--r-- | src/udp.c | 1 |
4 files changed, 16 insertions, 0 deletions
diff --git a/src/options.c b/src/options.c index 6cae7ee..6f36ba4 100644 --- a/src/options.c +++ b/src/options.c | |||
| @@ -254,6 +254,19 @@ static int opt_getboolean(lua_State *L, p_socket ps, int level, int name) | |||
| 254 | return 1; | 254 | return 1; |
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | int opt_get_error(lua_State *L, p_socket ps) | ||
| 258 | { | ||
| 259 | int val = 0; | ||
| 260 | socklen_t len = sizeof(val); | ||
| 261 | if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) { | ||
| 262 | lua_pushnil(L); | ||
| 263 | lua_pushstring(L, "getsockopt failed"); | ||
| 264 | return 2; | ||
| 265 | } | ||
| 266 | lua_pushstring(L, socket_strerror(val)); | ||
| 267 | return 1; | ||
| 268 | } | ||
| 269 | |||
| 257 | static int opt_setboolean(lua_State *L, p_socket ps, int level, int name) | 270 | static int opt_setboolean(lua_State *L, p_socket ps, int level, int name) |
| 258 | { | 271 | { |
| 259 | int val = auxiliar_checkboolean(L, 3); /* obj, name, bool */ | 272 | int val = auxiliar_checkboolean(L, 3); /* obj, name, bool */ |
diff --git a/src/options.h b/src/options.h index 55447f7..1cabd7d 100644 --- a/src/options.h +++ b/src/options.h | |||
| @@ -42,6 +42,7 @@ int opt_get_linger(lua_State *L, p_socket ps); | |||
| 42 | int opt_get_reuseaddr(lua_State *L, p_socket ps); | 42 | int opt_get_reuseaddr(lua_State *L, p_socket ps); |
| 43 | int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); | 43 | int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); |
| 44 | int opt_get_ip_multicast_if(lua_State *L, p_socket ps); | 44 | int opt_get_ip_multicast_if(lua_State *L, p_socket ps); |
| 45 | int opt_get_error(lua_State *L, p_socket ps); | ||
| 45 | 46 | ||
| 46 | /* invokes the appropriate option handler */ | 47 | /* invokes the appropriate option handler */ |
| 47 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); | 48 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); |
| @@ -73,6 +73,7 @@ static t_opt optget[] = { | |||
| 73 | {"reuseaddr", opt_get_reuseaddr}, | 73 | {"reuseaddr", opt_get_reuseaddr}, |
| 74 | {"tcp-nodelay", opt_get_tcp_nodelay}, | 74 | {"tcp-nodelay", opt_get_tcp_nodelay}, |
| 75 | {"linger", opt_get_linger}, | 75 | {"linger", opt_get_linger}, |
| 76 | {"error", opt_get_error}, | ||
| 76 | {NULL, NULL} | 77 | {NULL, NULL} |
| 77 | }; | 78 | }; |
| 78 | 79 | ||
| @@ -85,6 +85,7 @@ static t_opt optset[] = { | |||
| 85 | static t_opt optget[] = { | 85 | static t_opt optget[] = { |
| 86 | {"ip-multicast-if", opt_get_ip_multicast_if}, | 86 | {"ip-multicast-if", opt_get_ip_multicast_if}, |
| 87 | {"ip-multicast-loop", opt_get_ip_multicast_loop}, | 87 | {"ip-multicast-loop", opt_get_ip_multicast_loop}, |
| 88 | {"error", opt_get_error}, | ||
| 88 | {NULL, NULL} | 89 | {NULL, NULL} |
| 89 | }; | 90 | }; |
| 90 | 91 | ||
