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.33 by root, Mon May 26 04:14:32 2008 UTC vs.
Revision 1.39 by root, Mon Jan 5 14:41:35 2009 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 NFDBITS
58# define NFDBITS 0
57#endif 59#endif
58 60
59#if !EV_SELECT_USE_FD_SET 61#if !EV_SELECT_USE_FD_SET
60# define NFDBYTES (NFDBITS / 8) 62# define NFDBYTES (NFDBITS / 8)
61#endif 63#endif
75 SOCKET handle = anfds [fd].handle; 77 SOCKET handle = anfds [fd].handle;
76 #else 78 #else
77 int handle = fd; 79 int handle = fd;
78 #endif 80 #endif
79 81
82 /* FD_SET is broken on windows (it adds the fd to a set twice or more,
83 * which eventually leads to overflows). Need to call it only on changes.
84 */
85 #if EV_SELECT_IS_WINSOCKET
86 if ((oev ^ nev) & EV_READ)
87 #endif
80 if (nev & EV_READ) 88 if (nev & EV_READ)
81 FD_SET (handle, (fd_set *)vec_ri); 89 FD_SET (handle, (fd_set *)vec_ri);
82 else 90 else
83 FD_CLR (handle, (fd_set *)vec_ri); 91 FD_CLR (handle, (fd_set *)vec_ri);
84 92
93 #if EV_SELECT_IS_WINSOCKET
94 if ((oev ^ nev) & EV_WRITE)
95 #endif
85 if (nev & EV_WRITE) 96 if (nev & EV_WRITE)
86 FD_SET (handle, (fd_set *)vec_wi); 97 FD_SET (handle, (fd_set *)vec_wi);
87 else 98 else
88 FD_CLR (handle, (fd_set *)vec_wi); 99 FD_CLR (handle, (fd_set *)vec_wi);
89 100
90#else 101#else
91 102
92 int word = fd / NFDBITS; 103 int word = fd / NFDBITS;
93 fd_mask mask = 1UL << (fd % NFDBITS); 104 fd_mask mask = 1UL << (fd % NFDBITS);
166 #endif 177 #endif
167 178
168 #ifdef _WIN32 179 #ifdef _WIN32
169 /* select on windows errornously returns EINVAL when no fd sets have been 180 /* select on windows errornously returns EINVAL when no fd sets have been
170 * provided (this is documented). what microsoft doesn't tell you that this bug 181 * provided (this is documented). what microsoft doesn't tell you that this bug
171 * exists even when the fd sets are provided, so we have to check for this bug 182 * exists even when the fd sets _are_ provided, so we have to check for this bug
172 * here and emulate by sleeping manually. 183 * here and emulate by sleeping manually.
173 * we also get EINVAL when the timeout is invalid, but we ignore this case here 184 * we also get EINVAL when the timeout is invalid, but we ignore this case here
174 * and assume that EINVAL always means: you have to wait manually. 185 * and assume that EINVAL always means: you have to wait manually.
175 */ 186 */
176 if (errno == EINVAL) 187 if (errno == EINVAL)
183 if (errno == EBADF) 194 if (errno == EBADF)
184 fd_ebadf (EV_A); 195 fd_ebadf (EV_A);
185 else if (errno == ENOMEM && !syserr_cb) 196 else if (errno == ENOMEM && !syserr_cb)
186 fd_enomem (EV_A); 197 fd_enomem (EV_A);
187 else if (errno != EINTR) 198 else if (errno != EINTR)
188 syserr ("(libev) select"); 199 ev_syserr ("(libev) select");
189 200
190 return; 201 return;
191 } 202 }
192 203
193#if EV_SELECT_USE_FD_SET 204#if EV_SELECT_USE_FD_SET

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines