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/options.c | |
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/options.c')
-rw-r--r-- | src/options.c | 13 |
1 files changed, 13 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 */ |