Problem: ZMQ_TCP_RECV_BUFFER/SEND_BUFFER are redundant

These options are confusing and redundant. Their names suggest
they apply to the tcp:// transport, yet they are used for all
stream protocols. The methods zmq::set_tcp_receive_buffer and
zmq::set_tcp_send_buffer don't use these values at all, they use
ZMQ_SNDBUF and ZMQ_RCVBUF.

Solution: merge these new options into ZMQ_SNDBUF and ZMQ_RCVBUF.

This means defaulting these two options to 8192, and removing the
new options. We now have ZMQ_SNDBUF and ZMQ_RCVBUF being used both
for TCP socket control, and for input/output buffering.

Note: the default for SNDBUF and RCVBUF are otherwise 4096.
This commit is contained in:
Pieter Hintjens
2016-02-09 10:13:49 +01:00
parent 884c7f78e9
commit 7470c00d4d
7 changed files with 17 additions and 101 deletions

View File

@@ -203,10 +203,10 @@ void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
if (options.raw_socket) {
// no handshaking for raw sock, instantiate raw encoder and decoders
encoder = new (std::nothrow) raw_encoder_t (options.tcp_send_buffer_size);
encoder = new (std::nothrow) raw_encoder_t (options.sndbuf);
alloc_assert (encoder);
decoder = new (std::nothrow) raw_decoder_t (options.tcp_recv_buffer_size);
decoder = new (std::nothrow) raw_decoder_t (options.rcvbuf);
alloc_assert (decoder);
// disable handshaking for raw socket
@@ -385,12 +385,12 @@ void zmq::stream_engine_t::out_event ()
outpos = NULL;
outsize = encoder->encode (&outpos, 0);
while (outsize < options.tcp_send_buffer_size) {
while (outsize < (size_t) options.sndbuf) {
if ((this->*next_msg) (&tx_msg) == -1)
break;
encoder->load_msg (&tx_msg);
unsigned char *bufptr = outpos + outsize;
size_t n = encoder->encode (&bufptr, options.tcp_send_buffer_size - outsize);
size_t n = encoder->encode (&bufptr, options.sndbuf - outsize);
zmq_assert (n > 0);
if (outpos == NULL)
outpos = bufptr;
@@ -587,10 +587,10 @@ bool zmq::stream_engine_t::handshake ()
return false;
}
encoder = new (std::nothrow) v1_encoder_t (options.tcp_send_buffer_size);
encoder = new (std::nothrow) v1_encoder_t (options.sndbuf);
alloc_assert (encoder);
decoder = new (std::nothrow) v1_decoder_t (options.tcp_recv_buffer_size, options.maxmsgsize);
decoder = new (std::nothrow) v1_decoder_t (options.rcvbuf, options.maxmsgsize);
alloc_assert (decoder);
// We have already sent the message header.
@@ -635,11 +635,11 @@ bool zmq::stream_engine_t::handshake ()
}
encoder = new (std::nothrow) v1_encoder_t (
options.tcp_send_buffer_size);
options.sndbuf);
alloc_assert (encoder);
decoder = new (std::nothrow) v1_decoder_t (
options.tcp_recv_buffer_size, options.maxmsgsize);
options.rcvbuf, options.maxmsgsize);
alloc_assert (decoder);
}
else
@@ -650,19 +650,19 @@ bool zmq::stream_engine_t::handshake ()
return false;
}
encoder = new (std::nothrow) v2_encoder_t (options.tcp_send_buffer_size);
encoder = new (std::nothrow) v2_encoder_t (options.sndbuf);
alloc_assert (encoder);
decoder = new (std::nothrow) v2_decoder_t (
options.tcp_recv_buffer_size, options.maxmsgsize);
options.rcvbuf, options.maxmsgsize);
alloc_assert (decoder);
}
else {
encoder = new (std::nothrow) v2_encoder_t (options.tcp_send_buffer_size);
encoder = new (std::nothrow) v2_encoder_t (options.sndbuf);
alloc_assert (encoder);
decoder = new (std::nothrow) v2_decoder_t (
options.tcp_recv_buffer_size, options.maxmsgsize);
options.rcvbuf, options.maxmsgsize);
alloc_assert (decoder);
if (options.mechanism == ZMQ_NULL