diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.hpp | 4 | ||||
-rw-r--r-- | src/options.cpp | 19 | ||||
-rw-r--r-- | src/options.hpp | 3 | ||||
-rw-r--r-- | src/tcp_listener.cpp | 12 | ||||
-rw-r--r-- | src/tcp_listener.hpp | 3 | ||||
-rw-r--r-- | src/zmq_listener.cpp | 2 |
6 files changed, 32 insertions, 11 deletions
diff --git a/src/config.hpp b/src/config.hpp index 7d5ce52..4a0ad08 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -85,10 +85,6 @@ namespace zmq // possible latencies. clock_precision = 1000000, - // Maximal number of non-accepted connections that can be held by - // TCP listener object. - tcp_connection_backlog = 100, - // Maximum transport data unit size for PGM (TPDU). pgm_max_tpdu = 1500 }; diff --git a/src/options.cpp b/src/options.cpp index 5e92e74..ec85269 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -36,6 +36,7 @@ zmq::options_t::options_t () : type (-1), linger (-1), reconnect_ivl (100), + backlog (100), requires_in (false), requires_out (false), immediate_connect (true) @@ -150,6 +151,15 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, } reconnect_ivl = *((int*) optval_); return 0; + + case ZMQ_BACKLOG: + if (optvallen_ != sizeof (int)) { + errno = EINVAL; + return -1; + } + backlog = *((int*) optval_); + return 0; + } errno = EINVAL; @@ -269,6 +279,15 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) *optvallen_ = sizeof (int); return 0; + case ZMQ_BACKLOG: + if (*optvallen_ < sizeof (int)) { + errno = EINVAL; + return -1; + } + *((int*) optval_) = backlog; + *optvallen_ = sizeof (int); + return 0; + } errno = EINVAL; diff --git a/src/options.hpp b/src/options.hpp index 47a0d63..647e811 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -60,6 +60,9 @@ namespace zmq // Interval between attempts to reconnect, in milliseconds. int reconnect_ivl; + // Maximum backlog for pending connections. + int backlog; + // These options are never set by the user directly. Instead they are // provided by the specific socket type. bool requires_in; diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index a62bc04..3766682 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -42,7 +42,8 @@ zmq::tcp_listener_t::~tcp_listener_t () close (); } -int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) +int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_, + int backlog_) { // IPC protocol is not supported on Windows platform. if (strcmp (protocol_, "tcp") != 0 ) { @@ -81,7 +82,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) } // Listen for incomming connections. - rc = listen (s, 1); + rc = listen (s, backlog_); if (rc == SOCKET_ERROR) { wsa_error_to_errno (); return -1; @@ -161,7 +162,8 @@ zmq::tcp_listener_t::~tcp_listener_t () close (); } -int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) +int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_, + int backlog_) { if (strcmp (protocol_, "tcp") == 0 ) { @@ -201,7 +203,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) } // Listen for incomming connections. - rc = listen (s, tcp_connection_backlog); + rc = listen (s, backlog_); if (rc != 0) { close (); return -1; @@ -241,7 +243,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) } // Listen for incomming connections. - rc = listen (s, tcp_connection_backlog); + rc = listen (s, backlog_); if (rc != 0) { close (); return -1; diff --git a/src/tcp_listener.hpp b/src/tcp_listener.hpp index 3b60719..0ee90d8 100644 --- a/src/tcp_listener.hpp +++ b/src/tcp_listener.hpp @@ -36,7 +36,8 @@ namespace zmq ~tcp_listener_t (); // Start listening on the interface. - int set_address (const char *protocol_, const char *addr_); + int set_address (const char *protocol_, const char *addr_, + int backlog_); // Close the listening socket. int close (); diff --git a/src/zmq_listener.cpp b/src/zmq_listener.cpp index 14e5249..4f5dbb1 100644 --- a/src/zmq_listener.cpp +++ b/src/zmq_listener.cpp @@ -38,7 +38,7 @@ zmq::zmq_listener_t::~zmq_listener_t () int zmq::zmq_listener_t::set_address (const char *protocol_, const char *addr_) { - return tcp_listener.set_address (protocol_, addr_); + return tcp_listener.set_address (protocol_, addr_, options.backlog); } void zmq::zmq_listener_t::process_plug () |