summaryrefslogtreecommitdiff
path: root/epoll.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-02-10 16:39:46 -0500
committerNick Mathewson <nickm@torproject.org>2012-02-10 16:39:46 -0500
commitbac906c76119ed8c8915e3979160fac7e12eac05 (patch)
tree83de2c6ba7c64a4a2e7e9135566443691dcf10d6 /epoll.c
parent33fca629a6e140cffeb8c4ac74d3d1f1338bb1c8 (diff)
downloadlibevent-bac906c76119ed8c8915e3979160fac7e12eac05.tar.gz
Prefer epoll_create1 on Linuxen that have it
Diffstat (limited to 'epoll.c')
-rw-r--r--epoll.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/epoll.c b/epoll.c
index f1219e7d..8dc2515d 100644
--- 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);