diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-06-08 22:22:37 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-06-08 22:22:37 +0000 |
commit | 23dcfabcf1234aba4f2b2ed57a20f56e6e75fc16 (patch) | |
tree | 2a30e41434fea4ea27ba5718ad7918f40f361b06 /src | |
parent | d684be0cff116df0a3287b8883440b36460e0579 (diff) | |
download | luasocket-23dcfabcf1234aba4f2b2ed57a20f56e6e75fc16.tar.gz luasocket-23dcfabcf1234aba4f2b2ed57a20f56e6e75fc16.tar.bz2 luasocket-23dcfabcf1234aba4f2b2ed57a20f56e6e75fc16.zip |
Issue error when select is called with invalid parameters.
Some warnings removed (include string.h)
Diffstat (limited to 'src')
-rw-r--r-- | src/luasocket.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/luasocket.c b/src/luasocket.c index 9abfa09..5cea287 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <errno.h> | 22 | #include <errno.h> |
23 | #include <signal.h> | 23 | #include <signal.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | #include <string.h> | ||
25 | #include <ctype.h> | 26 | #include <ctype.h> |
26 | 27 | ||
27 | #include <lauxlib.h> | 28 | #include <lauxlib.h> |
@@ -620,7 +621,7 @@ int global_select(lua_State *L) | |||
620 | /* get rid of lua_next value and expose index */ | 621 | /* get rid of lua_next value and expose index */ |
621 | lua_pop(L, 1); | 622 | lua_pop(L, 1); |
622 | } | 623 | } |
623 | } | 624 | } else if (!lua_isnil(L, 1)) luaL_argerror(L, 1, "expected table or nil"); |
624 | /* get sockets we will test for writability into fd_set */ | 625 | /* get sockets we will test for writability into fd_set */ |
625 | if (lua_istable(L, 2)) { | 626 | if (lua_istable(L, 2)) { |
626 | lua_pushnil(L); | 627 | lua_pushnil(L); |
@@ -639,7 +640,7 @@ int global_select(lua_State *L) | |||
639 | /* get rid of lua_next value and expose index */ | 640 | /* get rid of lua_next value and expose index */ |
640 | lua_pop(L, 1); | 641 | lua_pop(L, 1); |
641 | } | 642 | } |
642 | } | 643 | } else if (!lua_isnil(L, 2)) luaL_argerror(L, 2, "expected table or nil"); |
643 | max++; | 644 | max++; |
644 | /* configure timeout value */ | 645 | /* configure timeout value */ |
645 | if (ms >= 0) { | 646 | if (ms >= 0) { |
@@ -1081,24 +1082,24 @@ static int set_option(lua_State *L, p_sock sock) | |||
1081 | int bool; | 1082 | int bool; |
1082 | if (!lua_isnumber(L, -1)) return 0; | 1083 | if (!lua_isnumber(L, -1)) return 0; |
1083 | bool = (int) lua_tonumber(L, -1); | 1084 | bool = (int) lua_tonumber(L, -1); |
1084 | err = setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, &bool, | 1085 | err = setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, |
1085 | sizeof(bool)); | 1086 | (char *) &bool, sizeof(bool)); |
1086 | return err >= 0; | 1087 | return err >= 0; |
1087 | } | 1088 | } |
1088 | case 1: { | 1089 | case 1: { |
1089 | int bool; | 1090 | int bool; |
1090 | if (!lua_isnumber(L, -1)) return 0; | 1091 | if (!lua_isnumber(L, -1)) return 0; |
1091 | bool = (int) lua_tonumber(L, -1); | 1092 | bool = (int) lua_tonumber(L, -1); |
1092 | err = setsockopt(sock->sock, SOL_SOCKET, SO_DONTROUTE, &bool, | 1093 | err = setsockopt(sock->sock, SOL_SOCKET, SO_DONTROUTE, |
1093 | sizeof(bool)); | 1094 | (char *) &bool, sizeof(bool)); |
1094 | return err >= 0; | 1095 | return err >= 0; |
1095 | } | 1096 | } |
1096 | case 2: { | 1097 | case 2: { |
1097 | int bool; | 1098 | int bool; |
1098 | if (!lua_isnumber(L, -1)) return 0; | 1099 | if (!lua_isnumber(L, -1)) return 0; |
1099 | bool = (int) lua_tonumber(L, -1); | 1100 | bool = (int) lua_tonumber(L, -1); |
1100 | err = setsockopt(sock->sock, SOL_SOCKET, SO_BROADCAST, &bool, | 1101 | err = setsockopt(sock->sock, SOL_SOCKET, SO_BROADCAST, |
1101 | sizeof(bool)); | 1102 | (char *) &bool, sizeof(bool)); |
1102 | return err >= 0; | 1103 | return err >= 0; |
1103 | } | 1104 | } |
1104 | case 3: { | 1105 | case 3: { |
@@ -1114,8 +1115,8 @@ static int set_option(lua_State *L, p_sock sock) | |||
1114 | if (!lua_isnumber(L, -1)) return 0; | 1115 | if (!lua_isnumber(L, -1)) return 0; |
1115 | linger.l_linger = lua_tonumber(L, -1); | 1116 | linger.l_linger = lua_tonumber(L, -1); |
1116 | lua_pop(L, 1); | 1117 | lua_pop(L, 1); |
1117 | err = setsockopt(sock->sock, SOL_SOCKET, SO_LINGER, &linger, | 1118 | err = setsockopt(sock->sock, SOL_SOCKET, SO_LINGER, |
1118 | sizeof(linger)); | 1119 | (char *) &linger, sizeof(linger)); |
1119 | return err >= 0; | 1120 | return err >= 0; |
1120 | } | 1121 | } |
1121 | default: return 0; | 1122 | default: return 0; |