… | |
… | |
88 | #else |
88 | #else |
89 | |
89 | |
90 | int word = fd / NFDBITS; |
90 | int word = fd / NFDBITS; |
91 | int mask = 1UL << (fd % NFDBITS); |
91 | int mask = 1UL << (fd % NFDBITS); |
92 | |
92 | |
93 | if (vec_max < word + 1) |
93 | if (expect_false (vec_max < word + 1)) |
94 | { |
94 | { |
95 | int new_max = word + 1; |
95 | int new_max = word + 1; |
96 | |
96 | |
97 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); |
97 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); |
98 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ |
98 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ |
… | |
… | |
132 | tv.tv_sec = (long)timeout; |
132 | tv.tv_sec = (long)timeout; |
133 | tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); |
133 | tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); |
134 | |
134 | |
135 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); |
135 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); |
136 | |
136 | |
137 | if (res < 0) |
137 | if (expect_false (res < 0)) |
138 | { |
138 | { |
139 | #if EV_SELECT_IS_WINSOCKET |
139 | #if EV_SELECT_IS_WINSOCKET |
140 | errno = WSAGetLastError (); |
140 | errno = WSAGetLastError (); |
141 | #endif |
141 | #endif |
142 | |
142 | |
… | |
… | |
166 | #endif |
166 | #endif |
167 | |
167 | |
168 | if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ; |
168 | if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ; |
169 | if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE; |
169 | if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE; |
170 | |
170 | |
171 | if (events) |
171 | if (expect_true (events)) |
172 | fd_event (EV_A_ fd, events); |
172 | fd_event (EV_A_ fd, events); |
173 | } |
173 | } |
174 | } |
174 | } |
175 | |
175 | |
176 | #else |
176 | #else |
… | |
… | |
189 | int events = 0; |
189 | int events = 0; |
190 | |
190 | |
191 | events |= word_r & mask ? EV_READ : 0; |
191 | events |= word_r & mask ? EV_READ : 0; |
192 | events |= word_w & mask ? EV_WRITE : 0; |
192 | events |= word_w & mask ? EV_WRITE : 0; |
193 | |
193 | |
194 | if (events) |
194 | if (expect_true (events)) |
195 | fd_event (EV_A_ word * NFDBITS + bit, events); |
195 | fd_event (EV_A_ word * NFDBITS + bit, events); |
196 | } |
196 | } |
197 | } |
197 | } |
198 | } |
198 | } |
199 | |
199 | |
… | |
… | |
201 | } |
201 | } |
202 | |
202 | |
203 | int inline_size |
203 | int inline_size |
204 | select_init (EV_P_ int flags) |
204 | select_init (EV_P_ int flags) |
205 | { |
205 | { |
206 | backend_fudge = 1e-2; /* needed to compensate for select returning early, very conservative */ |
206 | backend_fudge = 0; /* needed to compensate for select returning early, very conservative */ |
207 | backend_modify = select_modify; |
207 | backend_modify = select_modify; |
208 | backend_poll = select_poll; |
208 | backend_poll = select_poll; |
209 | |
209 | |
210 | #if EV_SELECT_USE_FD_SET |
210 | #if EV_SELECT_USE_FD_SET |
211 | vec_max = FD_SETSIZE / 32; |
211 | vec_max = FD_SETSIZE / 32; |