summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-10-17 10:23:58 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-10-17 10:23:58 +0200
commita780833683ed1f5bc4a112644836973f8282434b (patch)
tree1dbfad92c986294a2d6372fc7a65b74851c52102
parente8e2944f45eab3e22dc46ceac3225a886ca468ad (diff)
ZMQ_BACKLOG socket option added.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--doc/zmq_getsockopt.txt13
-rw-r--r--doc/zmq_setsockopt.txt13
-rw-r--r--include/zmq.h1
-rw-r--r--src/config.hpp4
-rw-r--r--src/options.cpp19
-rw-r--r--src/options.hpp3
-rw-r--r--src/tcp_listener.cpp12
-rw-r--r--src/tcp_listener.hpp3
-rw-r--r--src/zmq_listener.cpp2
9 files changed, 59 insertions, 11 deletions
diff --git a/doc/zmq_getsockopt.txt b/doc/zmq_getsockopt.txt
index 903d95f..4413d8b 100644
--- a/doc/zmq_getsockopt.txt
+++ b/doc/zmq_getsockopt.txt
@@ -239,6 +239,19 @@ Default value:: 100
Applicable socket types:: all
+ZMQ_BACKLOG: Retrieve maximum length of the queue of pending connections
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The 'ZMQ_RECONNECT' option shall retrieve maximum size of the
+pending connection backlog for connection-based transports. For details
+refer to your operating system documentation for the 'listen' function.
+
+[horizontal]
+Option value type:: int
+Option value unit:: connections
+Default value:: 100
+Applicable socket types:: all
+
+
ZMQ_FD: Retrieve file descriptor associated with the socket
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The 'ZMQ_FD' option shall retrieve file descriptor associated with the 0MQ
diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt
index e2747c0..248a6ac 100644
--- a/doc/zmq_setsockopt.txt
+++ b/doc/zmq_setsockopt.txt
@@ -245,6 +245,19 @@ Default value:: 100
Applicable socket types:: all
+ZMQ_BACKLOG: Set maximum length of the queue of pending connections
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The 'ZMQ_RECONNECT' option shall be set to specify maximum size of the
+pending connection backlog for connection-based transports. For details
+refer to your operating system documentation for the 'listen' function.
+
+[horizontal]
+Option value type:: int
+Option value unit:: connections
+Default value:: 100
+Applicable socket types:: all
+
+
RETURN VALUE
------------
The _zmq_setsockopt()_ function shall return zero if successful. Otherwise it
diff --git a/include/zmq.h b/include/zmq.h
index f4d2656..857fec7 100644
--- a/include/zmq.h
+++ b/include/zmq.h
@@ -193,6 +193,7 @@ ZMQ_EXPORT int zmq_term (void *context);
#define ZMQ_TYPE 16
#define ZMQ_LINGER 17
#define ZMQ_RECONNECT_IVL 18
+#define ZMQ_BACKLOG 19
/* Send/recv options. */
#define ZMQ_NOBLOCK 1
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 ()