]> granicus.if.org Git - libevent/commitdiff
Prefer epoll_create1 on Linuxen that have it
authorNick Mathewson <nickm@torproject.org>
Fri, 10 Feb 2012 21:39:46 +0000 (16:39 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 10 Feb 2012 21:39:46 +0000 (16:39 -0500)
configure.in
epoll.c

index 021f97c07eac10449437794a50f640b4509e9869..8c7e3e98479245c4c879025fab1839018f31b4fe 100644 (file)
@@ -310,6 +310,7 @@ AC_CHECK_FUNCS([ \
   arc4random_buf \
   clock_gettime \
   eventfd \
+  epoll_create1 \
   fcntl \
   getegid \
   geteuid \
diff --git a/epoll.c b/epoll.c
index f1219e7dfb6982c9a6fffb8a235ff0e00faf8760..8dc2515d0ab6ed8ea12e9c98990558961f63fa29 100644 (file)
--- a/epoll.c
+++ b/epoll.c
@@ -108,19 +108,24 @@ const struct eventop epollops = {
 static void *
 epoll_init(struct event_base *base)
 {
-       int epfd;
+       int epfd = -1;
        struct epollop *epollop;
 
-       /* Initialize the kernel queue.  (The size field is ignored since
-        * 2.6.8.) */
-       if ((epfd = epoll_create(32000)) == -1) {
-               if (errno != ENOSYS)
-                       event_warn("epoll_create");
-               return (NULL);
+#ifdef _EVENT_HAVE_EPOLL_CREATE1
+       /* First, try the shiny new epoll_create1 interface, if we have it. */
+       epfd = epoll_create1(EPOLL_CLOEXEC);
+#endif
+       if (epfd == -1) {
+               /* Initialize the kernel queue using the old interface.  (The
+               size field is ignored   since 2.6.8.) */
+               if ((epfd = epoll_create(32000)) == -1) {
+                       if (errno != ENOSYS)
+                               event_warn("epoll_create");
+                       return (NULL);
+               }
+               evutil_make_socket_closeonexec(epfd);
        }
 
-       evutil_make_socket_closeonexec(epfd);
-
        if (!(epollop = mm_calloc(1, sizeof(struct epollop)))) {
                close(epfd);
                return (NULL);