Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
5871ea5d
Commit
5871ea5d
authored
8 years ago
by
Constantin Rack
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2274 from bluca/cloexec
parents
16439e42
06055a7b
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
121 additions
and
5 deletions
+121
-5
CMakeLists.txt
CMakeLists.txt
+7
-0
acinclude.m4
acinclude.m4
+56
-1
ZMQSourceRunChecks.cmake
builds/cmake/Modules/ZMQSourceRunChecks.cmake
+15
-0
platform.hpp.in
builds/cmake/platform.hpp.in
+2
-0
configure.ac
configure.ac
+8
-2
epoll.cpp
src/epoll.cpp
+7
-0
signaler.cpp
src/signaler.cpp
+25
-2
CMakeLists.txt
tests/CMakeLists.txt
+1
-0
No files found.
CMakeLists.txt
View file @
5871ea5d
...
...
@@ -101,6 +101,10 @@ if (POLLER STREQUAL "")
set
(
CMAKE_REQUIRED_INCLUDES
)
if
(
HAVE_EPOLL
)
set
(
POLLER
"epoll"
)
check_function_exists
(
epoll_create1 HAVE_EPOLL_CLOEXEC
)
if
(
HAVE_EPOLL_CLOEXEC
)
set
(
ZMQ_USE_EPOLL_CLOEXEC 1
)
endif
()
endif
()
endif
()
...
...
@@ -179,6 +183,9 @@ check_include_files (ifaddrs.h ZMQ_HAVE_IFADDRS)
check_include_files
(
windows.h ZMQ_HAVE_WINDOWS
)
check_include_files
(
sys/uio.h ZMQ_HAVE_UIO
)
check_include_files
(
sys/eventfd.h ZMQ_HAVE_EVENTFD
)
if
(
ZMQ_HAVE_EVENTFD
)
zmq_check_efd_cloexec
()
endif
()
check_library_exists
(
ws2_32 fopen
""
HAVE_WS2_32
)
# TODO: Why doesn't something logical like WSAStartup work?
check_library_exists
(
ws2 fopen
""
HAVE_WS2
)
...
...
This diff is collapsed.
Click to expand it.
acinclude.m4
View file @
5871ea5d
...
...
@@ -614,6 +614,29 @@ int main (int argc, char *argv [])
AS_IF([test "x$libzmq_cv_sock_cloexec" = "xyes"], [$1], [$2])
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_EVENTFD_CLOEXEC([action-if-found], [action-if-not-found]) #
dnl # Check if EFD_CLOEXEC is supported #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_EVENTFD_CLOEXEC], [{
AC_CACHE_CHECK([whether EFD_CLOEXEC is supported], [libzmq_cv_efd_cloexec],
[AC_TRY_RUN([/* EFD_CLOEXEC test */
#include <sys/eventfd.h>
int main (int argc, char *argv [])
{
int s = eventfd (0, EFD_CLOEXEC);
return (s == -1);
}
],
[libzmq_cv_efd_cloexec="yes"],
[libzmq_cv_efd_cloexec="no"],
[libzmq_cv_efd_cloexec="not during cross-compile"]
)]
)
AS_IF([test "x$libzmq_cv_efd_cloexec" = "xyes"], [$1], [$2])
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_ATOMIC_INSTRINSICS([action-if-found], [action-if-not-found]) #
dnl # Check if compiler supoorts __atomic_Xxx intrinsics #
...
...
@@ -801,6 +824,7 @@ kqueue();
dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_EPOLL_RUN([action-if-found], [action-if-not-found]) #
dnl # LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC([action-if-found], [action-if-not-found]) #
dnl # Checks epoll polling system can actually run #
dnl # For cross-compile, only requires that epoll can link #
dnl ################################################################################
...
...
@@ -828,6 +852,30 @@ epoll_create(10);
)
}])
AC_DEFUN([LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC], [{
AC_RUN_IFELSE([
AC_LANG_PROGRAM([
#include <sys/epoll.h>
],[[
struct epoll_event t_ev;
int r;
r = epoll_create1(EPOLL_CLOEXEC);
return(r < 0);
]])],
[$1],[$2],[
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
#include <sys/epoll.h>
],[[
struct epoll_event t_ev;
epoll_create1(EPOLL_CLOEXEC);
]])],
[$1], [$2]
)
]
)
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_DEVPOLL([action-if-found], [action-if-not-found]) #
dnl # Checks devpoll polling system #
...
...
@@ -938,11 +986,18 @@ AC_DEFUN([LIBZMQ_CHECK_POLLER], [{
])
;;
epoll)
LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC([
AC_MSG_NOTICE([Using 'epoll' polling system with CLOEXEC])
AC_DEFINE(ZMQ_USE_EPOLL, 1, [Use 'epoll' polling system])
AC_DEFINE(ZMQ_USE_EPOLL_CLOEXEC, 1, [Use 'epoll' polling system with CLOEXEC])
poller_found=1
],[
LIBZMQ_CHECK_POLLER_EPOLL([
AC_MSG_NOTICE([Using 'epoll' polling system
])
AC_MSG_NOTICE([Using 'epoll' polling system with CLOEXEC
])
AC_DEFINE(ZMQ_USE_EPOLL, 1, [Use 'epoll' polling system])
poller_found=1
])
])
;;
devpoll)
LIBZMQ_CHECK_POLLER_DEVPOLL([
...
...
This diff is collapsed.
Click to expand it.
builds/cmake/Modules/ZMQSourceRunChecks.cmake
View file @
5871ea5d
...
...
@@ -16,6 +16,21 @@ int main(int argc, char *argv [])
ZMQ_HAVE_SOCK_CLOEXEC
)
endmacro
()
macro
(
zmq_check_efd_cloexec
)
message
(
STATUS
"Checking whether EFD_CLOEXEC is supported"
)
check_c_source_runs
(
"
#include <sys/eventfd.h>
int main(int argc, char *argv [])
{
int s = eventfd (0, EFD_CLOEXEC);
return(s == -1);
}
"
ZMQ_HAVE_EVENTFD_CLOEXEC
)
endmacro
()
# TCP keep-alives Checks.
macro
(
zmq_check_so_keepalive
)
...
...
This diff is collapsed.
Click to expand it.
builds/cmake/platform.hpp.in
View file @
5871ea5d
...
...
@@ -3,6 +3,7 @@
#cmakedefine ZMQ_USE_KQUEUE
#cmakedefine ZMQ_USE_EPOLL
#cmakedefine ZMQ_USE_EPOLL_CLOEXEC
#cmakedefine ZMQ_USE_DEVPOLL
#cmakedefine ZMQ_USE_POLL
#cmakedefine ZMQ_USE_SELECT
...
...
@@ -16,6 +17,7 @@
#cmakedefine ZMQ_HAVE_UIO
#cmakedefine ZMQ_HAVE_EVENTFD
#cmakedefine ZMQ_HAVE_EVENTFD_CLOEXEC
#cmakedefine ZMQ_HAVE_IFADDRS
#cmakedefine ZMQ_HAVE_SO_PEERCRED
...
...
This diff is collapsed.
Click to expand it.
configure.ac
View file @
5871ea5d
...
...
@@ -358,8 +358,14 @@ AC_ARG_ENABLE([eventfd],
if test "x$zmq_enable_eventfd" = "xyes"; then
# Check if we have eventfd.h header file.
AC_CHECK_HEADERS(sys/eventfd.h,
[AC_DEFINE(ZMQ_HAVE_EVENTFD, 1, [Have eventfd extension])])
AC_CHECK_HEADERS(sys/eventfd.h, [
AC_DEFINE(ZMQ_HAVE_EVENTFD, 1, [Have eventfd extension])
LIBZMQ_CHECK_EVENTFD_CLOEXEC([
AC_DEFINE([ZMQ_HAVE_EVENTFD_CLOEXEC],
[1],
[Whether EFD_CLOEXEC is defined and functioning.])
])
])
fi
# Conditionally build performance measurement tools
...
...
This diff is collapsed.
Click to expand it.
src/epoll.cpp
View file @
5871ea5d
...
...
@@ -48,7 +48,14 @@ zmq::epoll_t::epoll_t (const zmq::ctx_t &ctx_) :
ctx
(
ctx_
),
stopping
(
false
)
{
#ifdef ZMQ_USE_EPOLL_CLOEXEC
// Setting this option result in sane behaviour when exec() functions
// are used. Old sockets are closed and don't block TCP ports, avoid
// leaks, etc.
epoll_fd
=
epoll_create1
(
EPOLL_CLOEXEC
);
#else
epoll_fd
=
epoll_create
(
1
);
#endif
errno_assert
(
epoll_fd
!=
-
1
);
}
...
...
This diff is collapsed.
Click to expand it.
src/signaler.cpp
View file @
5871ea5d
...
...
@@ -381,7 +381,14 @@ void zmq::signaler_t::forked ()
int
zmq
::
signaler_t
::
make_fdpair
(
fd_t
*
r_
,
fd_t
*
w_
)
{
#if defined ZMQ_HAVE_EVENTFD
fd_t
fd
=
eventfd
(
0
,
0
);
int
flags
=
0
;
#if defined ZMQ_HAVE_EVENTFD_CLOEXEC
// Setting this option result in sane behaviour when exec() functions
// are used. Old sockets are closed and don't block TCP ports, avoid
// leaks, etc.
flags
|=
EFD_CLOEXEC
;
#endif
fd_t
fd
=
eventfd
(
0
,
flags
);
if
(
fd
==
-
1
)
{
errno_assert
(
errno
==
ENFILE
||
errno
==
EMFILE
);
*
w_
=
*
r_
=
-
1
;
...
...
@@ -637,13 +644,29 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
#else
// All other implementations support socketpair()
int
sv
[
2
];
int
rc
=
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
sv
);
int
type
=
SOCK_STREAM
;
// Setting this option result in sane behaviour when exec() functions
// are used. Old sockets are closed and don't block TCP ports, avoid
// leaks, etc.
#if defined ZMQ_HAVE_SOCK_CLOEXEC
type
|=
SOCK_CLOEXEC
;
#endif
int
rc
=
socketpair
(
AF_UNIX
,
type
,
0
,
sv
);
if
(
rc
==
-
1
)
{
errno_assert
(
errno
==
ENFILE
||
errno
==
EMFILE
);
*
w_
=
*
r_
=
-
1
;
return
-
1
;
}
else
{
// If there's no SOCK_CLOEXEC, let's try the second best option. Note that
// race condition can cause socket not to be closed (if fork happens
// between socket creation and this point).
#if !defined ZMQ_HAVE_SOCK_CLOEXEC && defined FD_CLOEXEC
rc
=
fcntl
(
sv
[
0
],
F_SETFD
,
FD_CLOEXEC
);
errno_assert
(
rc
!=
-
1
);
rc
=
fcntl
(
sv
[
1
],
F_SETFD
,
FD_CLOEXEC
);
errno_assert
(
rc
!=
-
1
);
#endif
*
w_
=
sv
[
0
];
*
r_
=
sv
[
1
];
return
0
;
...
...
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
View file @
5871ea5d
...
...
@@ -84,6 +84,7 @@ if(NOT WIN32)
test_router_mandatory_hwm
test_use_fd_ipc
test_use_fd_tcp
test_zmq_poll_fd
)
if
(
HAVE_FORK
)
list
(
APPEND tests test_fork
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment