]> granicus.if.org Git - libevent/commitdiff
detect kqueue bug in Mac OS X 10.4; from Nick Mathewson
authorNiels Provos <provos@gmail.com>
Wed, 11 May 2005 03:34:42 +0000 (03:34 +0000)
committerNiels Provos <provos@gmail.com>
Wed, 11 May 2005 03:34:42 +0000 (03:34 +0000)
svn:r165

kqueue.c

index 3558b9c4707633a581de79a0968392b1f4c129dc..4a8991d4c650a565c6d7aedb473620b150ab3da8 100644 (file)
--- a/kqueue.c
+++ b/kqueue.c
@@ -122,6 +122,27 @@ kq_init(void)
        }
        kqueueop->nevents = NEVENT;
 
+       /* Check for Mac OS X kqueue bug. */
+       kqueueop->changes[0].ident = -1;
+       kqueueop->changes[0].filter = EVFILT_READ;
+       kqueueop->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,
+               kqueueop->changes, 1, kqueueop->events, NEVENT, NULL) != 1 ||
+           kqueueop->events[0].ident != -1 ||
+           kqueueop->events[0].flags != EV_ERROR) {
+               event_warn("%s: detected broken kqueue; not using.", __func__);
+               free(kqueueop->changes);
+               free(kqueueop->events);
+               free(kqueueop);
+               close(kq);
+               return (NULL);
+       }
+
        return (kqueueop);
 }