ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_select.c
(Generate patch)

Comparing libev/ev_select.c (file contents):
Revision 1.28 by root, Sun Mar 16 16:38:23 2008 UTC vs.
Revision 1.30 by root, Thu May 22 14:05:14 2008 UTC

52#endif 52#endif
53 53
54#if EV_SELECT_IS_WINSOCKET 54#if EV_SELECT_IS_WINSOCKET
55# undef EV_SELECT_USE_FD_SET 55# undef EV_SELECT_USE_FD_SET
56# define EV_SELECT_USE_FD_SET 1 56# define EV_SELECT_USE_FD_SET 1
57# undef EINTR
58# define EINTR WSAEINTR
59# undef EBADF
60# define EBADF WSAENOTSOCK
61# undef ENOMEM
62# define ENOMEM (errno + 1)
63#endif 57#endif
64 58
65#if !EV_SELECT_USE_FD_SET 59#if !EV_SELECT_USE_FD_SET
66# define NFDBYTES (NFDBITS / 8) 60# define NFDBYTES (NFDBITS / 8)
67#endif 61#endif
96#else 90#else
97 91
98 int word = fd / NFDBITS; 92 int word = fd / NFDBITS;
99 fd_mask mask = 1UL << (fd % NFDBITS); 93 fd_mask mask = 1UL << (fd % NFDBITS);
100 94
101 if (expect_false (vec_max < word + 1)) 95 if (expect_false (vec_max <= word))
102 { 96 {
103 int new_max = word + 1; 97 int new_max = word + 1;
104 98
105 vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); 99 vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES);
106 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 */
144 138
145 if (expect_false (res < 0)) 139 if (expect_false (res < 0))
146 { 140 {
147 #if EV_SELECT_IS_WINSOCKET 141 #if EV_SELECT_IS_WINSOCKET
148 errno = WSAGetLastError (); 142 errno = WSAGetLastError ();
143 #endif
144 #ifdef WSABASEERR
145 /* on windows, select returns incompatible error codes, fix this */
146 if (errno >= WSABASEERR && errno < WSABASEERR + 1000)
147 if (errno == WSAENOTSOCK)
148 errno = EBADF;
149 else
150 errno -= WSABASEERR;
151 #endif
152
153 #ifdef _WIN32
154 /* select on windows errornously returns EINVAL when no fd sets have been
155 * provided (this is documented). what microsoft doesn't tell you that this bug
156 * exists even when the fd sets are provided, so we have to check for this bug
157 * here and emulate by sleeping manually.
158 * we also get EINVAL when the timeout is invalid, but we ignore this case here
159 * and assume that EINVAL always means: you have to wait manually.
160 */
161 if (errno == EINVAL)
162 {
163 ev_sleep (timeout);
164 return;
165 }
149 #endif 166 #endif
150 167
151 if (errno == EBADF) 168 if (errno == EBADF)
152 fd_ebadf (EV_A); 169 fd_ebadf (EV_A);
153 else if (errno == ENOMEM && !syserr_cb) 170 else if (errno == ENOMEM && !syserr_cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines