diff options
-rw-r--r-- | configure.ac | 12 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 18 |
2 files changed, 30 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index f64e18f4..69e672ea 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -293,6 +293,18 @@ if test "$enable_epoll" != "no"; then | |||
293 | fi | 293 | fi |
294 | fi | 294 | fi |
295 | 295 | ||
296 | if test "x$enable_epoll" = "xyes"; then | ||
297 | AC_CACHE_CHECK([for epoll_create1()], [mhd_cv_have_epoll_create1], [ | ||
298 | AC_LINK_IFELSE([ | ||
299 | AC_LANG_PROGRAM([[#include <sys/epoll.h>]], [[ | ||
300 | int fd; | ||
301 | fd = epoll_create1(EPOLL_CLOEXEC);]])], | ||
302 | [mhd_cv_have_epoll_create1=yes], | ||
303 | [mhd_cv_have_epoll_create1=no])]) | ||
304 | AS_IF([test "x$mhd_cv_have_epoll_create1" = "xyes"],[ | ||
305 | AC_DEFINE([[HAVE_EPOLL_CREATE1]], [[1]], [Define if you have epoll_create1 function.])]) | ||
306 | fi | ||
307 | |||
296 | if test "x$HAVE_POSIX_THREADS" = "xyes"; then | 308 | if test "x$HAVE_POSIX_THREADS" = "xyes"; then |
297 | # Check for pthread_setname_np() | 309 | # Check for pthread_setname_np() |
298 | SAVE_LIBS="$LIBS" | 310 | SAVE_LIBS="$LIBS" |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 314dabca..dbe0cb58 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -3333,7 +3333,11 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon) | |||
3333 | { | 3333 | { |
3334 | struct epoll_event event; | 3334 | struct epoll_event event; |
3335 | 3335 | ||
3336 | #ifdef HAVE_EPOLL_CREATE1 | ||
3336 | daemon->epoll_fd = epoll_create1 (EPOLL_CLOEXEC); | 3337 | daemon->epoll_fd = epoll_create1 (EPOLL_CLOEXEC); |
3338 | #else /* !HAVE_EPOLL_CREATE1 */ | ||
3339 | daemon->epoll_fd = epoll_create (MAX_EVENTS); | ||
3340 | #endif /* !HAVE_EPOLL_CREATE1 */ | ||
3337 | if (-1 == daemon->epoll_fd) | 3341 | if (-1 == daemon->epoll_fd) |
3338 | { | 3342 | { |
3339 | #if HAVE_MESSAGES | 3343 | #if HAVE_MESSAGES |
@@ -3343,6 +3347,20 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon) | |||
3343 | #endif | 3347 | #endif |
3344 | return MHD_NO; | 3348 | return MHD_NO; |
3345 | } | 3349 | } |
3350 | #ifndef HAVE_EPOLL_CREATE1 | ||
3351 | else | ||
3352 | { | ||
3353 | int fdflags = fcntl (daemon->epoll_fd, F_GETFD); | ||
3354 | if (0 > fdflags || 0 > fcntl (daemon->epoll_fd, F_SETFD, fdflags | FD_CLOEXEC)) | ||
3355 | { | ||
3356 | #if HAVE_MESSAGES | ||
3357 | MHD_DLOG (daemon, | ||
3358 | "Failed to change flags on epoll fd: %s\n", | ||
3359 | MHD_socket_last_strerr_ ()); | ||
3360 | #endif /* HAVE_MESSAGES */ | ||
3361 | } | ||
3362 | } | ||
3363 | #endif /* !HAVE_EPOLL_CREATE1 */ | ||
3346 | if (0 == EPOLL_CLOEXEC) | 3364 | if (0 == EPOLL_CLOEXEC) |
3347 | make_nonblocking_noninheritable (daemon, | 3365 | make_nonblocking_noninheritable (daemon, |
3348 | daemon->epoll_fd); | 3366 | daemon->epoll_fd); |