… | |
… | |
98 | |
98 | |
99 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); |
99 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); |
100 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ |
100 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ |
101 | vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES); |
101 | vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES); |
102 | vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */ |
102 | vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */ |
|
|
103 | #ifdef _WIN32 |
|
|
104 | vec_eo = ev_realloc (vec_eo, new_max * NFDBYTES); /* could free/malloc */ |
|
|
105 | #endif |
103 | |
106 | |
104 | for (; vec_max < new_max; ++vec_max) |
107 | for (; vec_max < new_max; ++vec_max) |
105 | ((fd_mask *)vec_ri) [vec_max] = |
108 | ((fd_mask *)vec_ri) [vec_max] = |
106 | ((fd_mask *)vec_wi) [vec_max] = 0; |
109 | ((fd_mask *)vec_wi) [vec_max] = 0; |
107 | } |
110 | } |
… | |
… | |
120 | static void |
123 | static void |
121 | select_poll (EV_P_ ev_tstamp timeout) |
124 | select_poll (EV_P_ ev_tstamp timeout) |
122 | { |
125 | { |
123 | struct timeval tv; |
126 | struct timeval tv; |
124 | int res; |
127 | int res; |
125 | |
128 | int fd_setsize; |
126 | #if EV_SELECT_USE_FD_SET |
|
|
127 | memcpy (vec_ro, vec_ri, sizeof (fd_set)); |
|
|
128 | memcpy (vec_wo, vec_wi, sizeof (fd_set)); |
|
|
129 | #else |
|
|
130 | memcpy (vec_ro, vec_ri, vec_max * NFDBYTES); |
|
|
131 | memcpy (vec_wo, vec_wi, vec_max * NFDBYTES); |
|
|
132 | #endif |
|
|
133 | |
129 | |
134 | tv.tv_sec = (long)timeout; |
130 | tv.tv_sec = (long)timeout; |
135 | tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); |
131 | tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); |
|
|
132 | |
|
|
133 | #if EV_SELECT_USE_FD_SET |
|
|
134 | fd_setsize = sizeof (fd_set); |
|
|
135 | #else |
|
|
136 | fd_setsize = vec_max * NFDBYTES; |
|
|
137 | #endif |
|
|
138 | |
|
|
139 | memcpy (vec_ro, vec_ri, fd_setsize); |
|
|
140 | memcpy (vec_wo, vec_wi, fd_setsize); |
136 | |
141 | |
137 | #ifdef _WIN32 |
142 | #ifdef _WIN32 |
138 | /* pass in the write set as except set. |
143 | /* pass in the write set as except set. |
139 | * the idea behind this is to work around a windows bug that causes |
144 | * the idea behind this is to work around a windows bug that causes |
140 | * errors to be reported as an exception and not by setting |
145 | * errors to be reported as an exception and not by setting |
141 | * the writable bit. this is so uncontrollably lame. |
146 | * the writable bit. this is so uncontrollably lame. |
142 | */ |
147 | */ |
|
|
148 | memcpy (vec_eo, vec_wi, fd_setsize); |
143 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, (fd_set *)vec_wo, &tv); |
149 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, (fd_set *)vec_eo, &tv); |
144 | #else |
150 | #else |
145 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); |
151 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); |
146 | #endif |
152 | #endif |
147 | |
153 | |
148 | if (expect_false (res < 0)) |
154 | if (expect_false (res < 0)) |
… | |
… | |
199 | int handle = fd; |
205 | int handle = fd; |
200 | #endif |
206 | #endif |
201 | |
207 | |
202 | if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ; |
208 | if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ; |
203 | if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE; |
209 | if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE; |
|
|
210 | #ifdef _WIN32 |
|
|
211 | if (FD_ISSET (handle, (fd_set *)vec_eo)) events |= EV_WRITE; |
|
|
212 | #endif |
204 | |
213 | |
205 | if (expect_true (events)) |
214 | if (expect_true (events)) |
206 | fd_event (EV_A_ fd, events); |
215 | fd_event (EV_A_ fd, events); |
207 | } |
216 | } |
208 | } |
217 | } |
… | |
… | |
213 | int word, bit; |
222 | int word, bit; |
214 | for (word = vec_max; word--; ) |
223 | for (word = vec_max; word--; ) |
215 | { |
224 | { |
216 | fd_mask word_r = ((fd_mask *)vec_ro) [word]; |
225 | fd_mask word_r = ((fd_mask *)vec_ro) [word]; |
217 | fd_mask word_w = ((fd_mask *)vec_wo) [word]; |
226 | fd_mask word_w = ((fd_mask *)vec_wo) [word]; |
|
|
227 | #ifdef _WIN32 |
|
|
228 | word_w |= ((fd_mask *)vec_eo) [word]; |
|
|
229 | #endif |
218 | |
230 | |
219 | if (word_r || word_w) |
231 | if (word_r || word_w) |
220 | for (bit = NFDBITS; bit--; ) |
232 | for (bit = NFDBITS; bit--; ) |
221 | { |
233 | { |
222 | fd_mask mask = 1UL << bit; |
234 | fd_mask mask = 1UL << bit; |
… | |
… | |
245 | vec_max = FD_SETSIZE / 32; |
257 | vec_max = FD_SETSIZE / 32; |
246 | vec_ri = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_ri); |
258 | vec_ri = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_ri); |
247 | vec_ro = ev_malloc (sizeof (fd_set)); |
259 | vec_ro = ev_malloc (sizeof (fd_set)); |
248 | vec_wi = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_wi); |
260 | vec_wi = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_wi); |
249 | vec_wo = ev_malloc (sizeof (fd_set)); |
261 | vec_wo = ev_malloc (sizeof (fd_set)); |
|
|
262 | #ifdef _WIN32 |
|
|
263 | vec_eo = ev_malloc (sizeof (fd_set)); |
|
|
264 | #endif |
250 | #else |
265 | #else |
251 | vec_max = 0; |
266 | vec_max = 0; |
252 | vec_ri = 0; |
267 | vec_ri = 0; |
253 | vec_ri = 0; |
268 | vec_ri = 0; |
254 | vec_wo = 0; |
269 | vec_wo = 0; |