Commit a31c5089 authored by hitstergtd's avatar hitstergtd

Problem: tune_tcp* related code has style issues

Solution: fix it
parent 95acb29b
...@@ -63,7 +63,7 @@ void zmq::tune_tcp_socket (fd_t s_) ...@@ -63,7 +63,7 @@ void zmq::tune_tcp_socket (fd_t s_)
#endif #endif
#ifdef ZMQ_HAVE_OPENVMS #ifdef ZMQ_HAVE_OPENVMS
// Disable delayed acknowledgements as they hurt latency is serious manner. // Disable delayed acknowledgements as they hurt latency significantly.
int nodelack = 1; int nodelack = 1;
rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack, rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
sizeof (int)); sizeof (int));
...@@ -93,7 +93,8 @@ void zmq::set_tcp_receive_buffer (fd_t sockfd_, int bufsize_) ...@@ -93,7 +93,8 @@ void zmq::set_tcp_receive_buffer (fd_t sockfd_, int bufsize_)
#endif #endif
} }
void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int keepalive_idle_, int keepalive_intvl_) void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_,
int keepalive_idle_, int keepalive_intvl_)
{ {
// These options are used only under certain #ifdefs below. // These options are used only under certain #ifdefs below.
LIBZMQ_UNUSED (keepalive_); LIBZMQ_UNUSED (keepalive_);
...@@ -110,34 +111,41 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int ...@@ -110,34 +111,41 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int
if (keepalive_ != -1) { if (keepalive_ != -1) {
tcp_keepalive keepalive_opts; tcp_keepalive keepalive_opts;
keepalive_opts.onoff = keepalive_; keepalive_opts.onoff = keepalive_;
keepalive_opts.keepalivetime = keepalive_idle_ != -1 ? keepalive_idle_ * 1000 : 7200000; keepalive_opts.keepalivetime = keepalive_idle_ != -1 ?
keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ? keepalive_intvl_ * 1000 : 1000; keepalive_idle_ * 1000 : 7200000;
keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ?
keepalive_intvl_ * 1000 : 1000;
DWORD num_bytes_returned; DWORD num_bytes_returned;
int rc = WSAIoctl(s_, SIO_KEEPALIVE_VALS, &keepalive_opts, sizeof(keepalive_opts), NULL, 0, &num_bytes_returned, NULL, NULL); int rc = WSAIoctl(s_, SIO_KEEPALIVE_VALS, &keepalive_opts,
sizeof(keepalive_opts), NULL, 0, &num_bytes_returned, NULL, NULL);
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
} }
#else #else
#ifdef ZMQ_HAVE_SO_KEEPALIVE #ifdef ZMQ_HAVE_SO_KEEPALIVE
if (keepalive_ != -1) { if (keepalive_ != -1) {
int rc = setsockopt (s_, SOL_SOCKET, SO_KEEPALIVE, (char*) &keepalive_, sizeof (int)); int rc = setsockopt (s_, SOL_SOCKET, SO_KEEPALIVE,
(char*) &keepalive_, sizeof (int));
errno_assert (rc == 0); errno_assert (rc == 0);
#ifdef ZMQ_HAVE_TCP_KEEPCNT #ifdef ZMQ_HAVE_TCP_KEEPCNT
if (keepalive_cnt_ != -1) { if (keepalive_cnt_ != -1) {
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPCNT, &keepalive_cnt_, sizeof (int)); int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPCNT,
&keepalive_cnt_, sizeof (int));
errno_assert (rc == 0); errno_assert (rc == 0);
} }
#endif // ZMQ_HAVE_TCP_KEEPCNT #endif // ZMQ_HAVE_TCP_KEEPCNT
#ifdef ZMQ_HAVE_TCP_KEEPIDLE #ifdef ZMQ_HAVE_TCP_KEEPIDLE
if (keepalive_idle_ != -1) { if (keepalive_idle_ != -1) {
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_idle_, sizeof (int)); int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPIDLE,
&keepalive_idle_, sizeof (int));
errno_assert (rc == 0); errno_assert (rc == 0);
} }
#else // ZMQ_HAVE_TCP_KEEPIDLE #else // ZMQ_HAVE_TCP_KEEPIDLE
#ifdef ZMQ_HAVE_TCP_KEEPALIVE #ifdef ZMQ_HAVE_TCP_KEEPALIVE
if (keepalive_idle_ != -1) { if (keepalive_idle_ != -1) {
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPALIVE, &keepalive_idle_, sizeof (int)); int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPALIVE,
&keepalive_idle_, sizeof (int));
errno_assert (rc == 0); errno_assert (rc == 0);
} }
#endif // ZMQ_HAVE_TCP_KEEPALIVE #endif // ZMQ_HAVE_TCP_KEEPALIVE
...@@ -145,7 +153,8 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int ...@@ -145,7 +153,8 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int
#ifdef ZMQ_HAVE_TCP_KEEPINTVL #ifdef ZMQ_HAVE_TCP_KEEPINTVL
if (keepalive_intvl_ != -1) { if (keepalive_intvl_ != -1) {
int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl_, sizeof (int)); int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPINTVL,
&keepalive_intvl_, sizeof (int));
errno_assert (rc == 0); errno_assert (rc == 0);
} }
#endif // ZMQ_HAVE_TCP_KEEPINTVL #endif // ZMQ_HAVE_TCP_KEEPINTVL
...@@ -165,7 +174,8 @@ void zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) ...@@ -165,7 +174,8 @@ void zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_)
int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, (char*) &timeout_, int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, (char*) &timeout_,
sizeof(timeout_)); sizeof(timeout_));
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
#elif defined (TCP_USER_TIMEOUT) // FIXME: should be ZMQ_HAVE_TCP_USER_TIMEOUT // FIXME: should be ZMQ_HAVE_TCP_USER_TIMEOUT
#elif defined (TCP_USER_TIMEOUT)
int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_, int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_,
sizeof(timeout_)); sizeof(timeout_));
errno_assert (rc == 0); errno_assert (rc == 0);
...@@ -195,8 +205,9 @@ void zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) ...@@ -195,8 +205,9 @@ void zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_)
)) ))
return -1; return -1;
// Circumvent a Windows bug; see https://support.microsoft.com/en-us/kb/201213 // Circumvent a Windows bug:
// and https://zeromq.jira.com/browse/LIBZMQ-195 // See https://support.microsoft.com/en-us/kb/201213
// See https://zeromq.jira.com/browse/LIBZMQ-195
if (nbytes == SOCKET_ERROR && last_error == WSAENOBUFS) if (nbytes == SOCKET_ERROR && last_error == WSAENOBUFS)
return 0; return 0;
......
...@@ -147,7 +147,8 @@ void zmq::tcp_connecter_t::out_event () ...@@ -147,7 +147,8 @@ void zmq::tcp_connecter_t::out_event ()
} }
tune_tcp_socket (fd); tune_tcp_socket (fd);
tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt,
options.tcp_keepalive_idle, options.tcp_keepalive_intvl);
tune_tcp_maxrt (fd, options.tcp_maxrt); tune_tcp_maxrt (fd, options.tcp_maxrt);
// remember our fd for ZMQ_SRCFD in messages // remember our fd for ZMQ_SRCFD in messages
......
...@@ -101,7 +101,8 @@ void zmq::tcp_listener_t::in_event () ...@@ -101,7 +101,8 @@ void zmq::tcp_listener_t::in_event ()
} }
tune_tcp_socket (fd); tune_tcp_socket (fd);
tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt,
options.tcp_keepalive_idle, options.tcp_keepalive_intvl);
tune_tcp_maxrt (fd, options.tcp_maxrt); tune_tcp_maxrt (fd, options.tcp_maxrt);
// remember our fd for ZMQ_SRCFD in messages // remember our fd for ZMQ_SRCFD in messages
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment