From f7b933f570545def0d654b9408c92b82ac0e54f4 Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Mon, 6 Jul 2015 18:05:31 +0300 Subject: [PATCH 1/3] LIBZMQ-195 allow explicitly setting sndbuf and rcvbuf to 0 (see https://support.microsoft.com/en-us/kb/201213) --- src/options.cpp | 4 ++-- src/pgm_socket.cpp | 4 ++-- src/socks_connecter.cpp | 4 ++-- src/tcp_connecter.cpp | 4 ++-- src/tcp_listener.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/options.cpp b/src/options.cpp index 6742f92e..da86c3fb 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -41,8 +41,8 @@ zmq::options_t::options_t () : rate (100), recovery_ivl (10000), multicast_hops (1), - sndbuf (0), - rcvbuf (0), + sndbuf (-1), + rcvbuf (-1), tos (0), type (-1), linger (-1), diff --git a/src/pgm_socket.cpp b/src/pgm_socket.cpp index 02655797..2557c668 100644 --- a/src/pgm_socket.cpp +++ b/src/pgm_socket.cpp @@ -196,14 +196,14 @@ int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_) { const int rcvbuf = (int) options.rcvbuf; - if (rcvbuf) { + if (rcvbuf >= 0) { if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof (rcvbuf))) goto err_abort; } const int sndbuf = (int) options.sndbuf; - if (sndbuf) { + if (sndbuf >= 0) { if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof (sndbuf))) goto err_abort; diff --git a/src/socks_connecter.cpp b/src/socks_connecter.cpp index bdc435ec..fb69ea7d 100644 --- a/src/socks_connecter.cpp +++ b/src/socks_connecter.cpp @@ -340,9 +340,9 @@ int zmq::socks_connecter_t::connect_to_proxy () unblock_socket (s); // Set the socket buffer limits for the underlying socket. - if (options.sndbuf != 0) + if (options.sndbuf >= 0) set_tcp_send_buffer (s, options.sndbuf); - if (options.rcvbuf != 0) + if (options.rcvbuf >= 0) set_tcp_receive_buffer (s, options.rcvbuf); // Set the IP Type-Of-Service for the underlying socket diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 17239a74..b328d487 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -258,9 +258,9 @@ int zmq::tcp_connecter_t::open () unblock_socket (s); // Set the socket buffer limits for the underlying socket. - if (options.sndbuf != 0) + if (options.sndbuf >= 0) set_tcp_send_buffer (s, options.sndbuf); - if (options.rcvbuf != 0) + if (options.rcvbuf >= 0) set_tcp_receive_buffer (s, options.rcvbuf); // Set the IP Type-Of-Service for the underlying socket diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 26cc3f0f..1b37a3b5 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -207,9 +207,9 @@ int zmq::tcp_listener_t::set_address (const char *addr_) set_ip_type_of_service (s, options.tos); // Set the socket buffer limits for the underlying socket. - if (options.sndbuf != 0) + if (options.sndbuf >= 0) set_tcp_send_buffer (s, options.sndbuf); - if (options.rcvbuf != 0) + if (options.rcvbuf >= 0) set_tcp_receive_buffer (s, options.rcvbuf); // Allow reusing of the address. From 8096990e451b8e76b28c6205748f55bc13d8448f Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Wed, 8 Jul 2015 11:40:23 +0300 Subject: [PATCH 2/3] update documentation regarding the sndbuf and rcvbuf parameters --- doc/zmq_getsockopt.txt | 6 ++---- doc/zmq_setsockopt.txt | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/zmq_getsockopt.txt b/doc/zmq_getsockopt.txt index 5213c0ea..a2a9d161 100644 --- a/doc/zmq_getsockopt.txt +++ b/doc/zmq_getsockopt.txt @@ -566,14 +566,12 @@ Applicable socket types:: all, when using multicast transports ZMQ_SNDBUF: Retrieve kernel transmit buffer size ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_SNDBUF' option shall retrieve the underlying kernel transmit buffer -size for the specified 'socket'. A value of zero means that the OS default is -in effect. For details refer to your operating system documentation for the -'SO_SNDBUF' socket option. +size for the specified 'socket'. For details refer to your operating system +documentation for the 'SO_SNDBUF' socket option. [horizontal] Option value type:: int Option value unit:: bytes -Default value:: 0 Applicable socket types:: all diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt index 3a8c83bb..cb89f0d0 100644 --- a/doc/zmq_setsockopt.txt +++ b/doc/zmq_setsockopt.txt @@ -660,14 +660,14 @@ Applicable socket types:: ZMQ_ROUTER ZMQ_SNDBUF: Set kernel transmit buffer size ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size -for the 'socket' to the specified size in bytes. A value of zero means leave +for the 'socket' to the specified size in bytes. A value of -1 means leave the OS default unchanged. For details please refer to your operating system documentation for the 'SO_SNDBUF' socket option. [horizontal] Option value type:: int Option value unit:: bytes -Default value:: 0 +Default value:: -1 Applicable socket types:: all From 7362f3af0f35d97645cda6ddb33fa8f0d7276246 Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Wed, 8 Jul 2015 11:58:42 +0300 Subject: [PATCH 3/3] update documentation regarding the rcvbuf parameter --- doc/zmq_getsockopt.txt | 6 ++---- doc/zmq_setsockopt.txt | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/zmq_getsockopt.txt b/doc/zmq_getsockopt.txt index a2a9d161..e011a473 100644 --- a/doc/zmq_getsockopt.txt +++ b/doc/zmq_getsockopt.txt @@ -450,14 +450,12 @@ Applicable socket types:: all, when using multicast transports ZMQ_RCVBUF: Retrieve kernel receive buffer size ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_RCVBUF' option shall retrieve the underlying kernel receive buffer -size for the specified 'socket'. A value of zero means that the OS default is -in effect. For details refer to your operating system documentation for the -'SO_RCVBUF' socket option. +size for the specified 'socket'. For details refer to your operating system +documentation for the 'SO_RCVBUF' socket option. [horizontal] Option value type:: int Option value unit:: bytes -Default value:: 0 Applicable socket types:: all diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt index cb89f0d0..d4146da5 100644 --- a/doc/zmq_setsockopt.txt +++ b/doc/zmq_setsockopt.txt @@ -469,14 +469,14 @@ Applicable socket types:: all, when using multicast transports ZMQ_RCVBUF: Set kernel receive buffer size ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for -the 'socket' to the specified size in bytes. A value of zero means leave the +the 'socket' to the specified size in bytes. A value of -1 means leave the OS default unchanged. For details refer to your operating system documentation for the 'SO_RCVBUF' socket option. [horizontal] Option value type:: int Option value unit:: bytes -Default value:: 0 +Default value:: -1 Applicable socket types:: all