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
4b303402
Commit
4b303402
authored
Apr 06, 2012
by
Sergey KHripchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more flexible keepalive options detection + awful options documentation
parent
0c3d9179
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
286 additions
and
28 deletions
+286
-28
acinclude.m4
acinclude.m4
+97
-15
configure.in
configure.in
+22
-5
zmq_getsockopt.txt
doc/zmq_getsockopt.txt
+63
-0
zmq_setsockopt.txt
doc/zmq_setsockopt.txt
+66
-0
ip.cpp
src/ip.cpp
+33
-4
options.cpp
src/options.cpp
+5
-4
No files found.
acinclude.m4
View file @
4b303402
...
...
@@ -604,10 +604,10 @@ int main (int argc, char *argv [])
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_
TCP_KEEPALIVE([action-if-found], [action-if-not-found])
#
dnl # LIBZMQ_CHECK_
SO_KEEPALIVE([action-if-found], [action-if-not-found])
#
dnl # Check if SO_KEEPALIVE is supported #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_
TCP
_KEEPALIVE], [{
AC_DEFUN([LIBZMQ_CHECK_
SO
_KEEPALIVE], [{
AC_MSG_CHECKING(whether SO_KEEPALIVE is supported)
AC_TRY_RUN([/* SO_KEEPALIVE test */
#include <sys/types.h>
...
...
@@ -622,19 +622,75 @@ int main (int argc, char *argv [])
);
}
],
[AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepalive="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_tcp_keepalive="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepalive="no"]
[AC_MSG_RESULT(yes) ; libzmq_cv_so_keepalive="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_so_keepalive="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_so_keepalive="no"]
)
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEPCNT([action-if-found], [action-if-not-found]) #
dnl # Check if TCP_KEEPCNT is supported #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPCNT], [{
AC_MSG_CHECKING(whether TCP_KEEPCNT is supported)
AC_TRY_RUN([/* TCP_KEEPCNT test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
int main (int argc, char *argv [])
{
int s, rc, opt = 1;
return (
((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPCNT, (char*) &opt, sizeof (int))) == -1)
);
}
],
[AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepcnt="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_tcp_keepcnt="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepcnt="no"]
)
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEP
ALIVE_OPTS([action-if-found], [action-if-not-found])
#
dnl # Check if TCP_KEEP
CNT, TCP_KEEPIDLE, TCP_KEEPINTVL are supported
#
dnl # LIBZMQ_CHECK_TCP_KEEP
IDLE([action-if-found], [action-if-not-found])
#
dnl # Check if TCP_KEEP
IDLE is supported
#
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPALIVE_OPTS], [{
AC_MSG_CHECKING(whether TCP_KEEPCNT TCP_KEEPIDLE TCP_KEEPINTVL are supported)
AC_TRY_RUN([/* TCP_KEEPCNT TCP_KEEPIDLE TCP_KEEPINTVL test */
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPIDLE], [{
AC_MSG_CHECKING(whether TCP_KEEPIDLE is supported)
AC_TRY_RUN([/* TCP_KEEPIDLE test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
int main (int argc, char *argv [])
{
int s, rc, opt = 1;
return (
((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPIDLE, (char*) &opt, sizeof (int))) == -1)
);
}
],
[AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepidle="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_tcp_keepidle="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepidle="no"]
)
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEPINTVL([action-if-found], [action-if-not-found]) #
dnl # Check if TCP_KEEPINTVL is supported #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPINTVL], [{
AC_MSG_CHECKING(whether TCP_KEEPINTVL is supported)
AC_TRY_RUN([/* TCP_KEEPINTVL test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
...
...
@@ -646,15 +702,41 @@ int main (int argc, char *argv [])
return (
((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPCNT, (char*) &opt, sizeof (int))) == -1) ||
((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPIDLE, (char*) &opt, sizeof (int))) == -1) ||
((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPINTVL, (char*) &opt, sizeof (int))) == -1)
);
}
],
[AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepalive_opts="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_tcp_keepalive_opts="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepalive_opts="no"]
[AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepintvl="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_tcp_keepintvl="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepintvl="no"]
)
}])
dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEPALIVE([action-if-found], [action-if-not-found]) #
dnl # Check if TCP_KEEPALIVE is supported #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPALIVE], [{
AC_MSG_CHECKING(whether TCP_KEEPALIVE is supported)
AC_TRY_RUN([/* TCP_KEEPALIVE test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
int main (int argc, char *argv [])
{
int s, rc, opt = 1;
return (
((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPALIVE, (char*) &opt, sizeof (int))) == -1)
);
}
],
[AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepalive="yes" ; $1],
[AC_MSG_RESULT(no) ; libzmq_cv_tcp_keepalive="no" ; $2],
[AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepalive="no"]
)
}])
...
...
configure.in
View file @
4b303402
...
...
@@ -383,15 +383,32 @@ LIBZMQ_CHECK_SOCK_CLOEXEC([AC_DEFINE(
[1],
[Whether SOCK_CLOEXEC is defined and functioning.])
])
LIBZMQ_CHECK_TCP_KEEPALIVE([AC_DEFINE(
[ZMQ_HAVE_TCP_KEEPALIVE],
# TCP keep-alives Checks.
LIBZMQ_CHECK_SO_KEEPALIVE([AC_DEFINE(
[ZMQ_HAVE_SO_KEEPALIVE],
[1],
[Whether SO_KEEPALIVE is supported.])
])
LIBZMQ_CHECK_TCP_KEEPALIVE_OPTS([AC_DEFINE(
[ZMQ_HAVE_TCP_KEEPALIVE_OPTS],
LIBZMQ_CHECK_TCP_KEEPCNT([AC_DEFINE(
[ZMQ_HAVE_TCP_KEEPCNT],
[1],
[Whether TCP_KEEPCNT is supported.])
])
LIBZMQ_CHECK_TCP_KEEPIDLE([AC_DEFINE(
[ZMQ_HAVE_TCP_KEEPIDLE],
[1],
[Whether TCP_KEEPIDLE is supported.])
])
LIBZMQ_CHECK_TCP_KEEPINTVL([AC_DEFINE(
[ZMQ_HAVE_TCP_KEEPINTVL],
[1],
[Whether TCP_KEEPINTVL is supported.])
])
LIBZMQ_CHECK_TCP_KEEPALIVE([AC_DEFINE(
[ZMQ_HAVE_TCP_KEEPALIVE],
[1],
[Whether TCP_KEEP
CNT, TCP_KEEPIDLE, TCP_KEEPINTVL are
supported.])
[Whether TCP_KEEP
ALIVE is
supported.])
])
# Subst LIBZMQ_EXTRA_CFLAGS & CXXFLAGS & LDFLAGS
...
...
doc/zmq_getsockopt.txt
View file @
4b303402
...
...
@@ -404,6 +404,69 @@ Option value unit:: N/A
Default value:: NULL
Applicable socket types:: all, when binding TCP or IPC transports
ZMQ_TCP_KEEPALIVE: Retrieve override TCP keepalives flag
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Retrieve override OS TCP keepalives on/off flag (maps to SO_KEEPALIVE socket option).
When equal to `1`(or `0`) TCP keepalives will be turned on(or off) for each new TCP connection
of ZeroMQ socket, `-1` value disables TCP keepalives adjustments.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
TCP keepalives are zero-length TCP packets automatically generated by OS
and transparrent to application socket, used to update state of TCP connection.
This also can be used to prevent the infrastructure (VPNs, NATs and similar) to terminate
connections with no activity.
[horizontal]
Option value type:: int
Option value unit:: -1,0,1
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
ZMQ_TCP_KEEPALIVE_IDLE: <dont know how to summarize it>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Retrieve option value to override the interval between the last data packet sent over
the TCP socket and the first keepalive probe (maps to TCP_KEEPCNT or TCP_KEEPALIVE socket option).
Default value `-1` disables adjustment.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
[horizontal]
Option value type:: int
Option value unit:: -1,>0
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
ZMQ_TCP_KEEPALIVE_CNT: <dont know how to summarize it>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Retrieve option value to override the number of unacknowledged keepalive probes
to send over the TCP socket before considering the connection dead and notifying
the application ZeroMQ layer (maps to TCP_KEEPCNT socket option).
Default value `-1` disables adjustment.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
[horizontal]
Option value type:: int
Option value unit:: -1,>0
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
ZMQ_TCP_KEEPALIVE_INTVL: <dont know how to summarize it>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Retrieve option value to override the interval between subsequential keepalive probes,
regardless of what the TCP connection has exchanged in the meantime
(maps to TCP_KEEPINTVL socket option).
Default value `-1` disables adjustment.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
[horizontal]
Option value type:: int
Option value unit:: -1,>0
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
RETURN VALUE
------------
The _zmq_getsockopt()_ function shall return zero if successful. Otherwise it
...
...
doc/zmq_setsockopt.txt
View file @
4b303402
...
...
@@ -367,6 +367,72 @@ Default value:: 0 (false)
Applicable socket types:: ZMQ_ROUTER
ZMQ_TCP_KEEPALIVE: Set TCP keepalives flag
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets the option to override TCP keepalives on/off flag (maps to SO_KEEPALIVE socket option).
When set to `1`(or `0`) TCP keepalives will be turned on(or off) for each new TCP connection
of ZeroMQ socket, `-1` value disables TCP keepalives adjustments.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
TCP keepalives are zero-length TCP packets automatically generated by OS
and transparrent to application socket, used to update state of TCP connection.
This also can be used to prevent the infrastructure (VPNs, NATs and similar) to terminate
connections with no activity.
[horizontal]
Option value type:: int
Option value unit:: -1,0,1
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
ZMQ_TCP_KEEPALIVE_IDLE: <dont know how to summarize it>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets option value to override the interval between the last data packet sent over
the TCP socket and the first keepalive probe (maps to TCP_KEEPCNT or TCP_KEEPALIVE socket option).
Default value `-1` disables adjustment.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
[horizontal]
Option value type:: int
Option value unit:: -1,>0
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
ZMQ_TCP_KEEPALIVE_CNT: <dont know how to summarize it>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets option value to override the number of unacknowledged keepalive probes
to send over the TCP socket before considering the connection dead and notifying
the application ZeroMQ layer (maps to TCP_KEEPCNT socket option).
Default value `-1` disables adjustment.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
[horizontal]
Option value type:: int
Option value unit:: -1,>0
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
ZMQ_TCP_KEEPALIVE_INTVL: <dont know how to summarize it>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets option value to override the interval between subsequential keepalive probes,
regardless of what the TCP connection has exchanged in the meantime
(maps to TCP_KEEPINTVL socket option).
Default value `-1` disables adjustment.
If the host OS does not support it then setsockopt() call will return `0` but leave this option equal to `-1`.
[horizontal]
Option value type:: int
Option value unit:: -1,>0
Default value:: -1 (leave for OS default)
Applicable socket types:: all, when using TCP transports.
RETURN VALUE
------------
The _zmq_setsockopt()_ function shall return zero if successful. Otherwise it
...
...
src/ip.cpp
View file @
4b303402
...
...
@@ -87,7 +87,7 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int
{
// Tuning TCP keep-alives if platform allows it
// All values = -1 means skip and leave it for OS
#ifdef ZMQ_HAVE_
TCP
_KEEPALIVE
#ifdef ZMQ_HAVE_
SO
_KEEPALIVE
if
(
keepalive_
!=
-
1
)
{
int
rc
=
setsockopt
(
s_
,
SOL_SOCKET
,
SO_KEEPALIVE
,
(
char
*
)
&
keepalive_
,
sizeof
(
int
));
#ifdef ZMQ_HAVE_WINDOWS
...
...
@@ -96,22 +96,51 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int
errno_assert
(
rc
==
0
);
#endif
#if
defined ZMQ_HAVE_TCP_KEEPALIVE_OPTS && !defined ZMQ_HAVE_WINDOWS
#if
def ZMQ_HAVE_TCP_KEEPCNT
if
(
keepalive_cnt_
!=
-
1
)
{
int
rc
=
setsockopt
(
s_
,
IPPROTO_TCP
,
TCP_KEEPCNT
,
&
keepalive_cnt_
,
sizeof
(
int
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
errno_assert
(
rc
==
0
);
#endif
}
#endif // ZMQ_HAVE_TCP_KEEPCNT
#ifdef ZMQ_HAVE_TCP_KEEPIDLE
if
(
keepalive_idle_
!=
-
1
)
{
int
rc
=
setsockopt
(
s_
,
IPPROTO_TCP
,
TCP_KEEPIDLE
,
&
keepalive_idle_
,
sizeof
(
int
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
errno_assert
(
rc
==
0
);
#endif
}
#else // ZMQ_HAVE_TCP_KEEPIDLE
#ifdef ZMQ_HAVE_TCP_KEEPALIVE
if
(
keepalive_idle_
!=
-
1
)
{
int
rc
=
setsockopt
(
s_
,
IPPROTO_TCP
,
TCP_KEEPALIVE
,
&
keepalive_idle_
,
sizeof
(
int
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
errno_assert
(
rc
==
0
);
#endif
}
#endif // ZMQ_HAVE_TCP_KEEPALIVE
#endif // ZMQ_HAVE_TCP_KEEPIDLE
#ifdef ZMQ_HAVE_TCP_KEEPINTVL
if
(
keepalive_intvl_
!=
-
1
)
{
int
rc
=
setsockopt
(
s_
,
IPPROTO_TCP
,
TCP_KEEPINTVL
,
&
keepalive_intvl_
,
sizeof
(
int
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
errno_assert
(
rc
==
0
);
}
#endif
}
#endif
#endif // ZMQ_HAVE_TCP_KEEPINTVL
}
#endif // ZMQ_HAVE_SO_KEEPALIVE
}
void
zmq
::
unblock_socket
(
fd_t
s_
)
...
...
src/options.cpp
View file @
4b303402
...
...
@@ -230,7 +230,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno
=
EINVAL
;
return
-
1
;
}
#if
def ZMQ_HAVE_TCP
_KEEPALIVE
#if
defined ZMQ_HAVE_SO
_KEEPALIVE
tcp_keepalive
=
val
;
#endif
return
0
;
...
...
@@ -247,7 +247,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno
=
EINVAL
;
return
-
1
;
}
#if defined ZMQ_HAVE_
TCP_KEEPALIVE && defined ZMQ_HAVE_TCP_KEEPALIVE_OPTS
#if defined ZMQ_HAVE_
SO_KEEPALIVE && defined ZMQ_HAVE_TCP_KEEPCNT
tcp_keepalive_cnt
=
val
;
#endif
return
0
;
...
...
@@ -264,7 +264,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno
=
EINVAL
;
return
-
1
;
}
#if defined ZMQ_HAVE_TCP_KEEPALIVE && defined ZMQ_HAVE_TCP_KEEPALIVE_OPTS
#if defined ZMQ_HAVE_SO_KEEPALIVE && (defined ZMQ_HAVE_TCP_KEEPIDLE || defined ZMQ_HAVE_TCP_KEEPALIVE)
tcp_keepalive_idle
=
val
;
#endif
return
0
;
...
...
@@ -281,7 +282,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno
=
EINVAL
;
return
-
1
;
}
#if defined ZMQ_HAVE_
TCP_KEEPALIVE && defined ZMQ_HAVE_TCP_KEEPALIVE_OPTS
#if defined ZMQ_HAVE_
SO_KEEPALIVE && defined ZMQ_HAVE_TCP_KEEPINTVL
tcp_keepalive_intvl
=
val
;
#endif
return
0
;
...
...
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