diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-20 07:20:26 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-20 07:20:26 +0000 |
commit | f20f4889bfe5a02cd9b77868b90cc8042352176a (patch) | |
tree | 339e085e385190ea5f3a9246c3a790c45036c61c /src/select.c | |
parent | 087b4f865d861162eb32a4081bb7c2087688919a (diff) | |
download | luasocket-f20f4889bfe5a02cd9b77868b90cc8042352176a.tar.gz luasocket-f20f4889bfe5a02cd9b77868b90cc8042352176a.tar.bz2 luasocket-f20f4889bfe5a02cd9b77868b90cc8042352176a.zip |
Changed prefix of function names to match module names.
Removed some warnings and useless code.
Diffstat (limited to 'src/select.c')
-rw-r--r-- | src/select.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/select.c b/src/select.c index 5a3d502..99b59f5 100644 --- a/src/select.c +++ b/src/select.c | |||
@@ -16,11 +16,12 @@ | |||
16 | /*=========================================================================*\ | 16 | /*=========================================================================*\ |
17 | * Internal function prototypes. | 17 | * Internal function prototypes. |
18 | \*=========================================================================*/ | 18 | \*=========================================================================*/ |
19 | static int getfd(lua_State *L); | 19 | static t_socket getfd(lua_State *L); |
20 | static int dirty(lua_State *L); | 20 | static int dirty(lua_State *L); |
21 | static int collect_fd(lua_State *L, int tab, int max_fd, int itab, fd_set *set); | 21 | static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd, |
22 | int itab, fd_set *set); | ||
22 | static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set); | 23 | static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set); |
23 | static void return_fd(lua_State *L, fd_set *set, int max_fd, | 24 | static void return_fd(lua_State *L, fd_set *set, t_socket max_fd, |
24 | int itab, int tab, int start); | 25 | int itab, int tab, int start); |
25 | static void make_assoc(lua_State *L, int tab); | 26 | static void make_assoc(lua_State *L, int tab); |
26 | static int global_select(lua_State *L); | 27 | static int global_select(lua_State *L); |
@@ -49,7 +50,8 @@ int select_open(lua_State *L) { | |||
49 | * Waits for a set of sockets until a condition is met or timeout. | 50 | * Waits for a set of sockets until a condition is met or timeout. |
50 | \*-------------------------------------------------------------------------*/ | 51 | \*-------------------------------------------------------------------------*/ |
51 | static int global_select(lua_State *L) { | 52 | static int global_select(lua_State *L) { |
52 | int rtab, wtab, itab, max_fd, ret, ndirty; | 53 | int rtab, wtab, itab, ret, ndirty; |
54 | t_socket max_fd; | ||
53 | fd_set rset, wset; | 55 | fd_set rset, wset; |
54 | t_timeout tm; | 56 | t_timeout tm; |
55 | double t = luaL_optnumber(L, 3, -1); | 57 | double t = luaL_optnumber(L, 3, -1); |
@@ -58,7 +60,7 @@ static int global_select(lua_State *L) { | |||
58 | lua_newtable(L); itab = lua_gettop(L); | 60 | lua_newtable(L); itab = lua_gettop(L); |
59 | lua_newtable(L); rtab = lua_gettop(L); | 61 | lua_newtable(L); rtab = lua_gettop(L); |
60 | lua_newtable(L); wtab = lua_gettop(L); | 62 | lua_newtable(L); wtab = lua_gettop(L); |
61 | max_fd = collect_fd(L, 1, -1, itab, &rset); | 63 | max_fd = collect_fd(L, 1, SOCKET_INVALID, itab, &rset); |
62 | ndirty = check_dirty(L, 1, rtab, &rset); | 64 | ndirty = check_dirty(L, 1, rtab, &rset); |
63 | t = ndirty > 0? 0.0: t; | 65 | t = ndirty > 0? 0.0: t; |
64 | timeout_init(&tm, t, -1); | 66 | timeout_init(&tm, t, -1); |
@@ -83,15 +85,15 @@ static int global_select(lua_State *L) { | |||
83 | /*=========================================================================*\ | 85 | /*=========================================================================*\ |
84 | * Internal functions | 86 | * Internal functions |
85 | \*=========================================================================*/ | 87 | \*=========================================================================*/ |
86 | static int getfd(lua_State *L) { | 88 | static t_socket getfd(lua_State *L) { |
87 | int fd = -1; | 89 | t_socket fd = SOCKET_INVALID; |
88 | lua_pushstring(L, "getfd"); | 90 | lua_pushstring(L, "getfd"); |
89 | lua_gettable(L, -2); | 91 | lua_gettable(L, -2); |
90 | if (!lua_isnil(L, -1)) { | 92 | if (!lua_isnil(L, -1)) { |
91 | lua_pushvalue(L, -2); | 93 | lua_pushvalue(L, -2); |
92 | lua_call(L, 1, 1); | 94 | lua_call(L, 1, 1); |
93 | if (lua_isnumber(L, -1)) | 95 | if (lua_isnumber(L, -1)) |
94 | fd = (int) lua_tonumber(L, -1); | 96 | fd = (t_socket) lua_tonumber(L, -1); |
95 | } | 97 | } |
96 | lua_pop(L, 1); | 98 | lua_pop(L, 1); |
97 | return fd; | 99 | return fd; |
@@ -110,13 +112,13 @@ static int dirty(lua_State *L) { | |||
110 | return is; | 112 | return is; |
111 | } | 113 | } |
112 | 114 | ||
113 | static int collect_fd(lua_State *L, int tab, int max_fd, | 115 | static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd, |
114 | int itab, fd_set *set) { | 116 | int itab, fd_set *set) { |
115 | int i = 1; | 117 | int i = 1; |
116 | if (lua_isnil(L, tab)) | 118 | if (lua_isnil(L, tab)) |
117 | return max_fd; | 119 | return max_fd; |
118 | while (1) { | 120 | while (1) { |
119 | int fd; | 121 | t_socket fd; |
120 | lua_pushnumber(L, i); | 122 | lua_pushnumber(L, i); |
121 | lua_gettable(L, tab); | 123 | lua_gettable(L, tab); |
122 | if (lua_isnil(L, -1)) { | 124 | if (lua_isnil(L, -1)) { |
@@ -124,9 +126,10 @@ static int collect_fd(lua_State *L, int tab, int max_fd, | |||
124 | break; | 126 | break; |
125 | } | 127 | } |
126 | fd = getfd(L); | 128 | fd = getfd(L); |
127 | if (fd >= 0) { | 129 | if (fd != SOCKET_INVALID) { |
128 | FD_SET(fd, set); | 130 | FD_SET(fd, set); |
129 | if (max_fd < fd) max_fd = fd; | 131 | if (max_fd == SOCKET_INVALID || max_fd < fd) |
132 | max_fd = fd; | ||
130 | lua_pushnumber(L, fd); | 133 | lua_pushnumber(L, fd); |
131 | lua_pushvalue(L, -2); | 134 | lua_pushvalue(L, -2); |
132 | lua_settable(L, itab); | 135 | lua_settable(L, itab); |
@@ -141,8 +144,8 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { | |||
141 | int ndirty = 0, i = 1; | 144 | int ndirty = 0, i = 1; |
142 | if (lua_isnil(L, tab)) | 145 | if (lua_isnil(L, tab)) |
143 | return 0; | 146 | return 0; |
144 | while (1) { | 147 | while (1) { |
145 | int fd; | 148 | t_socket fd; |
146 | lua_pushnumber(L, i); | 149 | lua_pushnumber(L, i); |
147 | lua_gettable(L, tab); | 150 | lua_gettable(L, tab); |
148 | if (lua_isnil(L, -1)) { | 151 | if (lua_isnil(L, -1)) { |
@@ -150,7 +153,7 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { | |||
150 | break; | 153 | break; |
151 | } | 154 | } |
152 | fd = getfd(L); | 155 | fd = getfd(L); |
153 | if (fd >= 0 && dirty(L)) { | 156 | if (fd != SOCKET_INVALID && dirty(L)) { |
154 | lua_pushnumber(L, ++ndirty); | 157 | lua_pushnumber(L, ++ndirty); |
155 | lua_pushvalue(L, -2); | 158 | lua_pushvalue(L, -2); |
156 | lua_settable(L, dtab); | 159 | lua_settable(L, dtab); |
@@ -162,9 +165,9 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { | |||
162 | return ndirty; | 165 | return ndirty; |
163 | } | 166 | } |
164 | 167 | ||
165 | static void return_fd(lua_State *L, fd_set *set, int max_fd, | 168 | static void return_fd(lua_State *L, fd_set *set, t_socket max_fd, |
166 | int itab, int tab, int start) { | 169 | int itab, int tab, int start) { |
167 | int fd; | 170 | t_socket fd; |
168 | for (fd = 0; fd < max_fd; fd++) { | 171 | for (fd = 0; fd < max_fd; fd++) { |
169 | if (FD_ISSET(fd, set)) { | 172 | if (FD_ISSET(fd, set)) { |
170 | lua_pushnumber(L, ++start); | 173 | lua_pushnumber(L, ++start); |