diff --git a/src/tcp.cpp b/src/tcp.cpp index 89e0e909..42789115 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -63,7 +63,7 @@ void zmq::tune_tcp_socket (fd_t s_) #endif #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; rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack, sizeof (int)); @@ -93,7 +93,8 @@ void zmq::set_tcp_receive_buffer (fd_t sockfd_, int bufsize_) #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. LIBZMQ_UNUSED (keepalive_); @@ -110,34 +111,41 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int if (keepalive_ != -1) { tcp_keepalive keepalive_opts; keepalive_opts.onoff = keepalive_; - keepalive_opts.keepalivetime = keepalive_idle_ != -1 ? keepalive_idle_ * 1000 : 7200000; - keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ? keepalive_intvl_ * 1000 : 1000; + keepalive_opts.keepalivetime = keepalive_idle_ != -1 ? + keepalive_idle_ * 1000 : 7200000; + keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ? + keepalive_intvl_ * 1000 : 1000; 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); } #else #ifdef ZMQ_HAVE_SO_KEEPALIVE 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); #ifdef ZMQ_HAVE_TCP_KEEPCNT 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); } #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)); + int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPIDLE, + &keepalive_idle_, sizeof (int)); errno_assert (rc == 0); } #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)); + int rc = setsockopt (s_, IPPROTO_TCP, TCP_KEEPALIVE, + &keepalive_idle_, sizeof (int)); errno_assert (rc == 0); } #endif // ZMQ_HAVE_TCP_KEEPALIVE @@ -145,7 +153,8 @@ void zmq::tune_tcp_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int #ifdef ZMQ_HAVE_TCP_KEEPINTVL 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); } #endif // ZMQ_HAVE_TCP_KEEPINTVL @@ -165,7 +174,8 @@ void zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, (char*) &timeout_, sizeof(timeout_)); 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_, sizeof(timeout_)); errno_assert (rc == 0); @@ -195,8 +205,9 @@ void zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) )) return -1; - // Circumvent a Windows bug; see https://support.microsoft.com/en-us/kb/201213 - // and https://zeromq.jira.com/browse/LIBZMQ-195 + // Circumvent a Windows bug: + // See https://support.microsoft.com/en-us/kb/201213 + // See https://zeromq.jira.com/browse/LIBZMQ-195 if (nbytes == SOCKET_ERROR && last_error == WSAENOBUFS) return 0; diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index b6f5b6ed..9ab39211 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -147,7 +147,8 @@ void zmq::tcp_connecter_t::out_event () } 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); // remember our fd for ZMQ_SRCFD in messages diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index b0c18dd6..ef326d9c 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -101,7 +101,8 @@ void zmq::tcp_listener_t::in_event () } 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); // remember our fd for ZMQ_SRCFD in messages