libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 8442f95d1db65bcee7ec9f9e515b4fa812030dbd
parent 4152f010b2eab67d2f84c1dc69179d6aee6a507d
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue,  3 Mar 2015 23:42:55 +0000

Check for epoll_create1() function, fix build for Android

Diffstat:
Mconfigure.ac | 12++++++++++++
Msrc/microhttpd/daemon.c | 18++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -293,6 +293,18 @@ if test "$enable_epoll" != "no"; then fi fi +if test "x$enable_epoll" = "xyes"; then + AC_CACHE_CHECK([for epoll_create1()], [mhd_cv_have_epoll_create1], [ + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[#include <sys/epoll.h>]], [[ +int fd; +fd = epoll_create1(EPOLL_CLOEXEC);]])], + [mhd_cv_have_epoll_create1=yes], + [mhd_cv_have_epoll_create1=no])]) + AS_IF([test "x$mhd_cv_have_epoll_create1" = "xyes"],[ + AC_DEFINE([[HAVE_EPOLL_CREATE1]], [[1]], [Define if you have epoll_create1 function.])]) +fi + if test "x$HAVE_POSIX_THREADS" = "xyes"; then # Check for pthread_setname_np() SAVE_LIBS="$LIBS" diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -3333,7 +3333,11 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon) { struct epoll_event event; +#ifdef HAVE_EPOLL_CREATE1 daemon->epoll_fd = epoll_create1 (EPOLL_CLOEXEC); +#else /* !HAVE_EPOLL_CREATE1 */ + daemon->epoll_fd = epoll_create (MAX_EVENTS); +#endif /* !HAVE_EPOLL_CREATE1 */ if (-1 == daemon->epoll_fd) { #if HAVE_MESSAGES @@ -3343,6 +3347,20 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon) #endif return MHD_NO; } +#ifndef HAVE_EPOLL_CREATE1 + else + { + int fdflags = fcntl (daemon->epoll_fd, F_GETFD); + if (0 > fdflags || 0 > fcntl (daemon->epoll_fd, F_SETFD, fdflags | FD_CLOEXEC)) + { +#if HAVE_MESSAGES + MHD_DLOG (daemon, + "Failed to change flags on epoll fd: %s\n", + MHD_socket_last_strerr_ ()); +#endif /* HAVE_MESSAGES */ + } + } +#endif /* !HAVE_EPOLL_CREATE1 */ if (0 == EPOLL_CLOEXEC) make_nonblocking_noninheritable (daemon, daemon->epoll_fd);