| 115 | } |
| 116 | |
| 117 | static void collect_fd(lua_State *L, int tab, int itab, |
| 118 | fd_set *set, t_socket *max_fd) { |
| 119 | int i = 1, n = 0; |
| 120 | /* nil is the same as an empty table */ |
| 121 | if (lua_isnil(L, tab)) return; |
| 122 | /* otherwise we need it to be a table */ |
| 123 | luaL_checktype(L, tab, LUA_TTABLE); |
| 124 | for ( ;; ) { |
| 125 | t_socket fd; |
| 126 | lua_pushnumber(L, i); |
| 127 | lua_gettable(L, tab); |
| 128 | if (lua_isnil(L, -1)) { |
| 129 | lua_pop(L, 1); |
| 130 | break; |
| 131 | } |
| 132 | /* getfd figures out if this is a socket */ |
| 133 | fd = getfd(L); |
| 134 | if (fd != SOCKET_INVALID) { |
| 135 | /* make sure we don't overflow the fd_set */ |
| 136 | #ifdef _WIN32 |
| 137 | if (n >= FD_SETSIZE) |
| 138 | luaL_argerror(L, tab, "too many sockets"); |
| 139 | #else |
| 140 | if (fd >= FD_SETSIZE) |
| 141 | luaL_argerror(L, tab, "descriptor too large for set size"); |
| 142 | #endif |
| 143 | FD_SET(fd, set); |
| 144 | n++; |
| 145 | /* keep track of the largest descriptor so far */ |
| 146 | if (*max_fd == SOCKET_INVALID || *max_fd < fd) |
| 147 | *max_fd = fd; |
| 148 | /* make sure we can map back from descriptor to the object */ |
| 149 | lua_pushnumber(L, (lua_Number) fd); |
| 150 | lua_pushvalue(L, -2); |
| 151 | lua_settable(L, itab); |
| 152 | } |
| 153 | lua_pop(L, 1); |
| 154 | i = i + 1; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { |
| 159 | int ndirty = 0, i = 1; |
no test coverage detected