Merge pull request #2842 from bluca/accept4

Problem: accept4 not available on all platforms
This commit is contained in:
Constantin Rack 2017-11-18 13:00:13 +01:00 committed by GitHub
commit b3bf51716e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 5 deletions

View File

@ -236,6 +236,10 @@ set (CMAKE_REQUIRED_INCLUDES stdlib.h)
check_function_exists (mkdtemp HAVE_MKDTEMP)
set (CMAKE_REQUIRED_INCLUDES)
set (CMAKE_REQUIRED_INCLUDES sys/socket.h)
check_function_exists (accept4 HAVE_ACCEPT4)
set (CMAKE_REQUIRED_INCLUDES)
add_definitions (-D_REENTRANT -D_THREAD_SAFE)
add_definitions (-DZMQ_CUSTOM_PLATFORM_HPP)

3
NEWS
View File

@ -212,6 +212,9 @@
* Fixed #2809 - optimize select() usage on Windows
* Fixed #2816 - add CMake and autoconf check for accept4, as it is not
available on old Linux releases, and fallback to accept + FD_CLOEXEC
* Fixed #2824 - ZMQ_REQ socket does not report ZMQ_POLLOUT when ZMQ_REQ_RELAXED
is set

View File

@ -36,6 +36,7 @@
#cmakedefine ZMQ_HAVE_PTHREAD_SETNAME_2
#cmakedefine ZMQ_HAVE_PTHREAD_SETNAME_3
#cmakedefine ZMQ_HAVE_PTHREAD_SET_NAME
#cmakedefine HAVE_ACCEPT4
#cmakedefine ZMQ_HAVE_OPENPGM
#cmakedefine ZMQ_MAKE_VALGRIND_HAPPY

View File

@ -71,6 +71,7 @@
# define ZMQ_HAVE_UIO 1
# define HAVE_CLOCK_GETTIME 1
# define HAVE_FORK 1
# define HAVE_ACCEPT4 1
#else
# error "No platform defined, abandoning"

View File

@ -621,7 +621,7 @@ AC_LANG_POP([C++])
# Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs fork posix_memalign mkdtemp)
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs fork posix_memalign mkdtemp accept4)
AC_CHECK_HEADERS([alloca.h])
# pthread_setname is non-posix, and there are at least 4 different implementations

View File

@ -382,7 +382,7 @@ zmq::fd_t zmq::ipc_listener_t::accept ()
// The situation where connection cannot be accepted due to insufficient
// resources is considered valid and treated by ignoring the connection.
zmq_assert (s != retired_fd);
#if defined ZMQ_HAVE_SOCK_CLOEXEC
#if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4
fd_t sock = ::accept4 (s, NULL, NULL, SOCK_CLOEXEC);
#else
fd_t sock = ::accept (s, NULL, NULL);
@ -394,7 +394,7 @@ zmq::fd_t zmq::ipc_listener_t::accept ()
return retired_fd;
}
#if !defined ZMQ_HAVE_SOCK_CLOEXEC && defined FD_CLOEXEC
#if (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) && defined FD_CLOEXEC
// Race condition can cause socket not to be closed (if fork happens
// between accept and this point).
int rc = fcntl (sock, F_SETFD, FD_CLOEXEC);

View File

@ -281,7 +281,7 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
#else
socklen_t ss_len = sizeof (ss);
#endif
#if defined ZMQ_HAVE_SOCK_CLOEXEC
#if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4
fd_t sock = ::accept4 (s, (struct sockaddr *) &ss, &ss_len, SOCK_CLOEXEC);
#else
fd_t sock = ::accept (s, (struct sockaddr *) &ss, &ss_len);
@ -311,7 +311,7 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
}
#endif
#if !defined ZMQ_HAVE_SOCK_CLOEXEC && defined FD_CLOEXEC
#if (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) && defined FD_CLOEXEC
// Race condition can cause socket not to be closed (if fork happens
// between accept and this point).
int rc = fcntl (sock, F_SETFD, FD_CLOEXEC);