X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/8ee8df9cf84f6ae595eb82ebe7e5eb119112087e..b8c10cda08d48348f422bb3d31f019584cf252c9:/ev_kqueue.c?ds=sidebyside diff --git a/ev_kqueue.c b/ev_kqueue.c index e68654f..4bbcf39 100644 --- a/ev_kqueue.c +++ b/ev_kqueue.c @@ -1,4 +1,3 @@ - /* * Copyright 2007 Marc Alexander Lehmann * Copyright 2000-2002 Niels Provos @@ -56,10 +55,14 @@ kqueue_change (int fd, int filter, int flags, int fflags) ke->fflags = fflags; } +#ifndef NOTE_EOF +# define NOTE_EOF 0 +#endif + static void kqueue_modify (int fd, int oev, int nev) { - if ((oev ^ new) & EV_READ) + if ((oev ^ nev) & EV_READ) { if (nev & EV_READ) kqueue_change (fd, EVFILT_READ, EV_ADD, NOTE_EOF); @@ -67,7 +70,7 @@ kqueue_modify (int fd, int oev, int nev) kqueue_change (fd, EVFILT_READ, EV_DELETE, 0); } - if ((oev ^ new) & EV_WRITE) + if ((oev ^ nev) & EV_WRITE) { if (nev & EV_WRITE) kqueue_change (fd, EVFILT_WRITE, EV_ADD, NOTE_EOF); @@ -106,14 +109,14 @@ kqueue_poll (ev_tstamp timeout) * an event we are still processing. In that case * the data field is set to ENOENT. */ - if (events [i].data == EBADF) - fd_kill (events [i].ident); + if (kq_events [i].data == EBADF) + fd_kill (kq_events [i].ident); } else - event ( - events [i].ident, - events [i].filter == EVFILT_READ ? EV_READ - : events [i].filter == EVFILT_WRITE ? EV_WRITE + fd_event ( + kq_events [i].ident, + kq_events [i].filter == EVFILT_READ ? EV_READ + : kq_events [i].filter == EVFILT_WRITE ? EV_WRITE : 0 ); } @@ -127,51 +130,37 @@ kqueue_poll (ev_tstamp timeout) } static void -kqueue_init (struct event_base *base) +kqueue_init (int flags) { - /* Initalize the kernel queue */ - if ((kq_fd = kqueue ()) == -1) - { - free (kqueueop); - return; - } + struct kevent ch, ev; - /* Initalize fields */ - kq_changes = malloc (NEVENT * sizeof (struct kevent)); - if (!kq_changes) + /* Initalize the kernel queue */ + if ((kq_fd = kqueue ()) < 0) return; - events = malloc (NEVENT * sizeof (struct kevent)); - if (!events) - { - free (kq_changes); - return; - } - /* Check for Mac OS X kqueue bug. */ - kq_changes [0].ident = -1; - kq_changes [0].filter = EVFILT_READ; - kq_changes [0].flags = EV_ADD; + ch.ident = -1; + ch.filter = EVFILT_READ; + ch.flags = EV_ADD; + /* * If kqueue works, then kevent will succeed, and it will - * stick an error in events[0]. If kqueue is broken, then + * stick an error in ev. If kqueue is broken, then * kevent will fail. */ - if (kevent (kq_fd, kq_changes, 1, kq_events, NEVENT, NULL) != 1 - || kq_events[0].ident != -1 - || kq_events[0].flags != EV_ERROR) + if (kevent (kq_fd, &ch, 1, &ev, 1, 0) != 1 + || ev.ident != -1 + || ev.flags != EV_ERROR) { /* detected broken kqueue */ - free (kq_changes); - free (kq_events); close (kq_fd); return; } ev_method = EVMETHOD_KQUEUE; method_fudge = 1e-3; /* needed to compensate for kevent returning early */ - method_modify = kq_modify; - method_poll = kq_poll; + method_modify = kqueue_modify; + method_poll = kqueue_poll; kq_eventmax = 64; /* intiial number of events receivable per poll */ kq_events = malloc (sizeof (struct kevent) * kq_eventmax);