… | |
… | |
93 | else |
93 | else |
94 | FD_CLR (handle, (fd_set *)vec_wi); |
94 | FD_CLR (handle, (fd_set *)vec_wi); |
95 | |
95 | |
96 | #else |
96 | #else |
97 | |
97 | |
98 | int word = fd / NFDBITS; |
98 | int word = fd / NFDBITS; |
99 | int mask = 1UL << (fd % NFDBITS); |
99 | fd_mask mask = 1UL << (fd % NFDBITS); |
100 | |
100 | |
101 | if (expect_false (vec_max < word + 1)) |
101 | if (expect_false (vec_max <= word)) |
102 | { |
102 | { |
103 | int new_max = word + 1; |
103 | int new_max = word + 1; |
104 | |
104 | |
105 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); |
105 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); |
106 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ |
106 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ |
107 | vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES); |
107 | vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES); |
108 | vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */ |
108 | vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */ |
109 | |
109 | |
110 | for (; vec_max < new_max; ++vec_max) |
110 | for (; vec_max < new_max; ++vec_max) |
111 | ((fd_mask *)vec_ri)[vec_max] = |
111 | ((fd_mask *)vec_ri) [vec_max] = |
112 | ((fd_mask *)vec_wi)[vec_max] = 0; |
112 | ((fd_mask *)vec_wi) [vec_max] = 0; |
113 | } |
113 | } |
114 | |
114 | |
115 | ((fd_mask *)vec_ri) [word] |= mask; |
115 | ((fd_mask *)vec_ri) [word] |= mask; |
116 | if (!(nev & EV_READ)) |
116 | if (!(nev & EV_READ)) |
117 | ((fd_mask *)vec_ri) [word] &= ~mask; |
117 | ((fd_mask *)vec_ri) [word] &= ~mask; |
… | |
… | |
144 | |
144 | |
145 | if (expect_false (res < 0)) |
145 | if (expect_false (res < 0)) |
146 | { |
146 | { |
147 | #if EV_SELECT_IS_WINSOCKET |
147 | #if EV_SELECT_IS_WINSOCKET |
148 | errno = WSAGetLastError (); |
148 | errno = WSAGetLastError (); |
|
|
149 | #endif |
|
|
150 | #ifdef WSABASEERR |
|
|
151 | /* on windows, select returns incompatible error codes, fix this */ |
|
|
152 | if (errno >= WSABASEERR && errno < WSABASEERR + 1000) |
|
|
153 | if (errno == WSAENOTSOCK) |
|
|
154 | errno = EBADF; |
|
|
155 | else |
|
|
156 | errno -= WSABASEERR; |
|
|
157 | #endif |
|
|
158 | |
|
|
159 | #ifdef _WIN32 |
|
|
160 | /* select on windows errornously returns EINVAL when no fd sets have been |
|
|
161 | * provided (this is documented). what microsoft doesn't tell you that this bug |
|
|
162 | * exists even when the fd sets are provided, so we have to check for this bug |
|
|
163 | * here and emulate by sleeping manually. |
|
|
164 | * we also get EINVAL when the timeout is invalid, but we ignore this case here |
|
|
165 | * and assume that EINVAL always means: you have to wait manually. |
|
|
166 | */ |
|
|
167 | if (errno == EINVAL) |
|
|
168 | { |
|
|
169 | ev_sleep (timeout); |
|
|
170 | return; |
|
|
171 | } |
149 | #endif |
172 | #endif |
150 | |
173 | |
151 | if (errno == EBADF) |
174 | if (errno == EBADF) |
152 | fd_ebadf (EV_A); |
175 | fd_ebadf (EV_A); |
153 | else if (errno == ENOMEM && !syserr_cb) |
176 | else if (errno == ENOMEM && !syserr_cb) |