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

Comparing libev/ev_kqueue.c (file contents):
Revision 1.24 by root, Fri Nov 23 13:08:57 2007 UTC vs.
Revision 1.25 by root, Fri Nov 23 19:13:33 2007 UTC

85 kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); 85 kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
86 } 86 }
87 87
88 ts.tv_sec = (time_t)timeout; 88 ts.tv_sec = (time_t)timeout;
89 ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); 89 ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9);
90 res = kevent (kqueue_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); 90 res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts);
91 kqueue_changecnt = 0; 91 kqueue_changecnt = 0;
92 92
93 if (res < 0) 93 if (res < 0)
94 { 94 {
95 if (errno != EINTR) 95 if (errno != EINTR)
154kqueue_init (EV_P_ int flags) 154kqueue_init (EV_P_ int flags)
155{ 155{
156 struct kevent ch, ev; 156 struct kevent ch, ev;
157 157
158 /* Initalize the kernel queue */ 158 /* Initalize the kernel queue */
159 if ((kqueue_fd = kqueue ()) < 0) 159 if ((backend_fd = kqueue ()) < 0)
160 return 0; 160 return 0;
161 161
162 fcntl (kqueue_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ 162 fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */
163 163
164 /* Check for Mac OS X kqueue bug. */ 164 /* Check for Mac OS X kqueue bug. */
165 ch.ident = -1; 165 ch.ident = -1;
166 ch.filter = EVFILT_READ; 166 ch.filter = EVFILT_READ;
167 ch.flags = EV_ADD; 167 ch.flags = EV_ADD;
169 /* 169 /*
170 * If kqueue works, then kevent will succeed, and it will 170 * If kqueue works, then kevent will succeed, and it will
171 * stick an error in ev. If kqueue is broken, then 171 * stick an error in ev. If kqueue is broken, then
172 * kevent will fail. 172 * kevent will fail.
173 */ 173 */
174 if (kevent (kqueue_fd, &ch, 1, &ev, 1, 0) != 1 174 if (kevent (backend_fd, &ch, 1, &ev, 1, 0) != 1
175 || ev.ident != -1 175 || ev.ident != -1
176 || ev.flags != EV_ERROR) 176 || ev.flags != EV_ERROR)
177 { 177 {
178 /* detected broken kqueue */ 178 /* detected broken kqueue */
179 close (kqueue_fd); 179 close (backend_fd);
180 return 0; 180 return 0;
181 } 181 }
182 182
183 backend_fudge = 1e-3; /* needed to compensate for kevent returning early */ 183 backend_fudge = 1e-3; /* needed to compensate for kevent returning early */
184 backend_modify = kqueue_modify; 184 backend_modify = kqueue_modify;
195} 195}
196 196
197static void 197static void
198kqueue_destroy (EV_P) 198kqueue_destroy (EV_P)
199{ 199{
200 close (kqueue_fd); 200 close (backend_fd);
201 201
202 ev_free (kqueue_events); 202 ev_free (kqueue_events);
203 ev_free (kqueue_changes); 203 ev_free (kqueue_changes);
204} 204}
205 205
206static void 206static void
207kqueue_fork (EV_P) 207kqueue_fork (EV_P)
208{ 208{
209 close (kqueue_fd); 209 close (backend_fd);
210 210
211 while ((kqueue_fd = kqueue ()) < 0) 211 while ((backend_fd = kqueue ()) < 0)
212 syserr ("(libev) kqueue"); 212 syserr ("(libev) kqueue");
213 213
214 fcntl (kqueue_fd, F_SETFD, FD_CLOEXEC); 214 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
215 215
216 /* re-register interest in fds */ 216 /* re-register interest in fds */
217 fd_rearm_all (EV_A); 217 fd_rearm_all (EV_A);
218} 218}
219 219

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines