- /* Check for Mac OS X kqueue bug. */
- kq_changes [0].ident = -1;
- kq_changes [0].filter = EVFILT_READ;
- kq_changes [0].flags = EV_ADD;
- /*
- * If kqueue works, then kevent will succeed, and it will
- * stick an error in events[0]. 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)
- {
- /* detected broken kqueue */
- free (kq_changes);
- free (kq_events);
- close (kq_fd);
- return;
- }
+ kqueue_eventmax = 64; /* initial number of events receivable per poll */
+ kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
+
+ kqueue_changes = 0;
+ kqueue_changemax = 0;
+ kqueue_changecnt = 0;
+
+ return EVBACKEND_KQUEUE;
+}
+
+static void
+kqueue_destroy (EV_P)
+{
+ close (backend_fd);
+
+ ev_free (kqueue_events);
+ ev_free (kqueue_changes);
+}
+
+static void
+kqueue_fork (EV_P)
+{
+ close (backend_fd);
+
+ while ((backend_fd = kqueue ()) < 0)
+ syserr ("(libev) kqueue");