aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/select.c b/src/select.c
index 8e47d0e..0931b73 100644
--- a/src/select.c
+++ b/src/select.c
@@ -2,7 +2,7 @@
2* Select implementation 2* Select implementation
3* LuaSocket toolkit 3* LuaSocket toolkit
4* 4*
5* RCS ID: $Id$ 5* RCS ID: $Id: select.c,v 1.23 2009/05/27 09:31:35 diego Exp $
6\*=========================================================================*/ 6\*=========================================================================*/
7#include <string.h> 7#include <string.h>
8 8
@@ -95,8 +95,10 @@ static t_socket getfd(lua_State *L) {
95 if (!lua_isnil(L, -1)) { 95 if (!lua_isnil(L, -1)) {
96 lua_pushvalue(L, -2); 96 lua_pushvalue(L, -2);
97 lua_call(L, 1, 1); 97 lua_call(L, 1, 1);
98 if (lua_isnumber(L, -1)) 98 if (lua_isnumber(L, -1)) {
99 fd = (t_socket) lua_tonumber(L, -1); 99 double numfd = lua_tonumber(L, -1);
100 fd = (numfd >= 0.0)? (t_socket) numfd: SOCKET_INVALID;
101 }
100 } 102 }
101 lua_pop(L, 1); 103 lua_pop(L, 1);
102 return fd; 104 return fd;
@@ -134,8 +136,13 @@ static void collect_fd(lua_State *L, int tab, int itab,
134 fd = getfd(L); 136 fd = getfd(L);
135 if (fd != SOCKET_INVALID) { 137 if (fd != SOCKET_INVALID) {
136 /* make sure we don't overflow the fd_set */ 138 /* make sure we don't overflow the fd_set */
139#ifdef _WIN32
137 if (n >= FD_SETSIZE) 140 if (n >= FD_SETSIZE)
138 luaL_argerror(L, tab, "too many sockets"); 141 luaL_argerror(L, tab, "too many sockets");
142#else
143 if (fd >= FD_SETSIZE)
144 luaL_argerror(L, tab, "descriptor too large for set size");
145#endif
139 FD_SET(fd, set); 146 FD_SET(fd, set);
140 n++; 147 n++;
141 /* keep track of the largest descriptor so far */ 148 /* keep track of the largest descriptor so far */