From 5815b768b9b6075d8743fe32947006af853fa9e8 Mon Sep 17 00:00:00 2001 From: Olaf Mandel Date: Thu, 13 Feb 2014 15:54:06 +0100 Subject: [PATCH] Add ZMQ_MAX_SOCKETS_MAX to zmq_ctx_get() The new options allows querying the maximum allowed number of sockets. This is system dependent and cannot be encoded in the include file as a preprocessor macro: for ZMQ_USE_SELECT, this depends on the FD_SETSIZE macro at time of library compilation, not at time of include file use. --- doc/zmq_ctx_get.txt | 5 +++++ doc/zmq_ctx_set.txt | 3 ++- include/zmq.h | 1 + src/ctx.cpp | 4 ++++ tests/test_ctx_options.cpp | 8 ++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/zmq_ctx_get.txt b/doc/zmq_ctx_get.txt index 980a2a90..5361453d 100644 --- a/doc/zmq_ctx_get.txt +++ b/doc/zmq_ctx_get.txt @@ -31,6 +31,11 @@ ZMQ_MAX_SOCKETS: Get maximum number of sockets The 'ZMQ_MAX_SOCKETS' argument returns the maximum number of sockets allowed for this context. +ZMQ_MAX_SOCKETS_MAX: Get largest configurable number of sockets +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The 'ZMQ_MAX_SOCKETS_MAX' argument returns the largest number of sockets +that linkzmq:zmq_ctx_set[3] will accept. + ZMQ_IPV6: Set IPv6 option ~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_IPV6' argument returns the IPv6 option for the context. diff --git a/doc/zmq_ctx_set.txt b/doc/zmq_ctx_set.txt index 461444bc..0049dff2 100644 --- a/doc/zmq_ctx_set.txt +++ b/doc/zmq_ctx_set.txt @@ -35,7 +35,8 @@ Default value:: 1 ZMQ_MAX_SOCKETS: Set maximum number of sockets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_MAX_SOCKETS' argument sets the maximum number of sockets allowed -on the context. +on the context. You can query the maximal allowed value with +linkzmq:zmq_ctx_get[3] using 'option_name' set to 'ZMQ_MAX_SOCKETS_MAX'. [horizontal] Default value:: 1024 diff --git a/include/zmq.h b/include/zmq.h index 961c2836..9a1a413c 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -178,6 +178,7 @@ ZMQ_EXPORT void zmq_version (int *major, int *minor, int *patch); /* Context options */ #define ZMQ_IO_THREADS 1 #define ZMQ_MAX_SOCKETS 2 +#define ZMQ_MAX_SOCKETS_MAX 3 /* Default for new contexts */ #define ZMQ_IO_THREADS_DFLT 1 diff --git a/src/ctx.cpp b/src/ctx.cpp index b11c5a3e..b69c7143 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -24,6 +24,7 @@ #include #endif +#include #include #include @@ -204,6 +205,9 @@ int zmq::ctx_t::get (int option_) if (option_ == ZMQ_MAX_SOCKETS) rc = max_sockets; else + if (option_ == ZMQ_MAX_SOCKETS_MAX) + rc = clipped_maxsocket (std::numeric_limits::max()); + else if (option_ == ZMQ_IO_THREADS) rc = io_thread_count; else diff --git a/tests/test_ctx_options.cpp b/tests/test_ctx_options.cpp index 1e598386..c01d42aa 100644 --- a/tests/test_ctx_options.cpp +++ b/tests/test_ctx_options.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . */ +#include #include "testutil.hpp" int main (void) @@ -29,6 +30,13 @@ int main (void) assert (ctx); assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT); +#if defined(ZMQ_USE_SELECT) + assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS_MAX) == ZMQ_MAX_SOCKETS_DFLT); +#elif defined(ZMQ_USE_POLL) || defined(ZMQ_USE_EPOLL) \ + || defined(ZMQ_USE_DEVPOLL) || defined(ZMQ_USE_KQUEUE) + assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS_MAX) + == std::numeric_limits::max()); +#endif assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT); assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);