X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/228b0b302ab0857b23efad5a8b2429de2c0ccc00..692ca25945e1a987acf66bd845ce70a61aa7b160:/ev_kqueue.c diff --git a/ev_kqueue.c b/ev_kqueue.c index 8282fea..07d16e4 100644 --- a/ev_kqueue.c +++ b/ev_kqueue.c @@ -85,7 +85,12 @@ kqueue_poll (EV_P_ ev_tstamp timeout) kqueue_changecnt = 0; if (res < 0) - return; + { + if (errno != EINTR) + syserr ("(libev) kevent"); + + return; + } for (i = 0; i < res; ++i) { @@ -118,9 +123,9 @@ kqueue_poll (EV_P_ ev_tstamp timeout) if (expect_false (res == kqueue_eventmax)) { - free (kqueue_events); + ev_free (kqueue_events); kqueue_eventmax = array_roundsize (kqueue_events, kqueue_eventmax << 1); - kqueue_events = malloc (sizeof (struct kevent) * kqueue_eventmax); + kqueue_events = ev_malloc (sizeof (struct kevent) * kqueue_eventmax); } } @@ -133,6 +138,8 @@ kqueue_init (EV_P_ int flags) if ((kqueue_fd = kqueue ()) < 0) return 0; + fcntl (kqueue_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ + /* Check for Mac OS X kqueue bug. */ ch.ident = -1; ch.filter = EVFILT_READ; @@ -157,8 +164,40 @@ kqueue_init (EV_P_ int flags) method_poll = kqueue_poll; kqueue_eventmax = 64; /* intiial number of events receivable per poll */ - kqueue_events = malloc (sizeof (struct kevent) * kqueue_eventmax); + kqueue_events = ev_malloc (sizeof (struct kevent) * kqueue_eventmax); + + kqueue_changes = 0; + kqueue_changemax = 0; + kqueue_changecnt = 0; return EVMETHOD_KQUEUE; } +static void +kqueue_destroy (EV_P) +{ + close (kqueue_fd); + + ev_free (kqueue_events); + ev_free (kqueue_changes); +} + +static void +kqueue_fork (EV_P) +{ + for (;;) + { + kqueue_fd = kqueue (); + + if (kqueue_fd >= 0) + break; + + syserr ("(libev) kqueue"); + } + + fcntl (kqueue_fd, F_SETFD, FD_CLOEXEC); + + /* re-register interest in fds */ + fd_rearm_all (EV_A); +} +