aboutsummaryrefslogtreecommitdiff
path: root/src/options.c
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2013-05-29 04:20:33 -0700
committerDiego Nehab <diego.nehab@gmail.com>2013-05-29 04:20:33 -0700
commit5341131cd07bf4f66ce242980b5f3cfbbf45ea12 (patch)
tree2a5db457e38cdf3de1f29df4d0217999c5cd306d /src/options.c
parentb84a5f3d08b1dc9d1003506bbca53e11264e8693 (diff)
parent1de617e3550366076737e804f1e28891605db89c (diff)
downloadluasocket-5341131cd07bf4f66ce242980b5f3cfbbf45ea12.tar.gz
luasocket-5341131cd07bf4f66ce242980b5f3cfbbf45ea12.tar.bz2
luasocket-5341131cd07bf4f66ce242980b5f3cfbbf45ea12.zip
Merge pull request #43 from moteus/moteus-getopt-error
Add. Allow get `error` option to socket.
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c13
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
257int 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
257static int opt_setboolean(lua_State *L, p_socket ps, int level, int name) 270static 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 */