From: Niels Provos Date: Wed, 11 May 2005 03:34:42 +0000 (+0000) Subject: detect kqueue bug in Mac OS X 10.4; from Nick Mathewson X-Git-Tag: release-1.1b~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57fafe6b5f9b416367f01e77540c7f72ae019c5d;p=libevent detect kqueue bug in Mac OS X 10.4; from Nick Mathewson svn:r165 --- diff --git a/kqueue.c b/kqueue.c index 3558b9c4..4a8991d4 100644 --- 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); }