Issue error when select is called with invalid parameters.

Some warnings removed (include string.h)
This commit is contained in:
Diego Nehab 2001-06-08 22:22:37 +00:00
parent d684be0cff
commit 23dcfabcf1

View File

@ -22,6 +22,7 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <lauxlib.h> #include <lauxlib.h>
@ -620,7 +621,7 @@ int global_select(lua_State *L)
/* get rid of lua_next value and expose index */ /* get rid of lua_next value and expose index */
lua_pop(L, 1); lua_pop(L, 1);
} }
} } else if (!lua_isnil(L, 1)) luaL_argerror(L, 1, "expected table or nil");
/* get sockets we will test for writability into fd_set */ /* get sockets we will test for writability into fd_set */
if (lua_istable(L, 2)) { if (lua_istable(L, 2)) {
lua_pushnil(L); lua_pushnil(L);
@ -639,7 +640,7 @@ int global_select(lua_State *L)
/* get rid of lua_next value and expose index */ /* get rid of lua_next value and expose index */
lua_pop(L, 1); lua_pop(L, 1);
} }
} } else if (!lua_isnil(L, 2)) luaL_argerror(L, 2, "expected table or nil");
max++; max++;
/* configure timeout value */ /* configure timeout value */
if (ms >= 0) { if (ms >= 0) {
@ -1081,24 +1082,24 @@ static int set_option(lua_State *L, p_sock sock)
int bool; int bool;
if (!lua_isnumber(L, -1)) return 0; if (!lua_isnumber(L, -1)) return 0;
bool = (int) lua_tonumber(L, -1); bool = (int) lua_tonumber(L, -1);
err = setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE, &bool, err = setsockopt(sock->sock, SOL_SOCKET, SO_KEEPALIVE,
sizeof(bool)); (char *) &bool, sizeof(bool));
return err >= 0; return err >= 0;
} }
case 1: { case 1: {
int bool; int bool;
if (!lua_isnumber(L, -1)) return 0; if (!lua_isnumber(L, -1)) return 0;
bool = (int) lua_tonumber(L, -1); bool = (int) lua_tonumber(L, -1);
err = setsockopt(sock->sock, SOL_SOCKET, SO_DONTROUTE, &bool, err = setsockopt(sock->sock, SOL_SOCKET, SO_DONTROUTE,
sizeof(bool)); (char *) &bool, sizeof(bool));
return err >= 0; return err >= 0;
} }
case 2: { case 2: {
int bool; int bool;
if (!lua_isnumber(L, -1)) return 0; if (!lua_isnumber(L, -1)) return 0;
bool = (int) lua_tonumber(L, -1); bool = (int) lua_tonumber(L, -1);
err = setsockopt(sock->sock, SOL_SOCKET, SO_BROADCAST, &bool, err = setsockopt(sock->sock, SOL_SOCKET, SO_BROADCAST,
sizeof(bool)); (char *) &bool, sizeof(bool));
return err >= 0; return err >= 0;
} }
case 3: { case 3: {
@ -1114,8 +1115,8 @@ static int set_option(lua_State *L, p_sock sock)
if (!lua_isnumber(L, -1)) return 0; if (!lua_isnumber(L, -1)) return 0;
linger.l_linger = lua_tonumber(L, -1); linger.l_linger = lua_tonumber(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
err = setsockopt(sock->sock, SOL_SOCKET, SO_LINGER, &linger, err = setsockopt(sock->sock, SOL_SOCKET, SO_LINGER,
sizeof(linger)); (char *) &linger, sizeof(linger));
return err >= 0; return err >= 0;
} }
default: return 0; default: return 0;