Commit 568cc1ad authored by Richard Newton's avatar Richard Newton

Get maximum number of sockets it can handle from poller_t

parent 97cfa64d
...@@ -38,6 +38,14 @@ ...@@ -38,6 +38,14 @@
#define ZMQ_CTX_TAG_VALUE_GOOD 0xabadcafe #define ZMQ_CTX_TAG_VALUE_GOOD 0xabadcafe
#define ZMQ_CTX_TAG_VALUE_BAD 0xdeadbeef #define ZMQ_CTX_TAG_VALUE_BAD 0xdeadbeef
int clipped_maxsocket(int max_requested)
{
if (max_requested >= zmq::poller_t::max_fds() && zmq::poller_t::max_fds() != -1)
max_requested = zmq::poller_t::max_fds() - 1; // -1 because we need room for the repear mailbox.
return max_requested;
}
zmq::ctx_t::ctx_t () : zmq::ctx_t::ctx_t () :
tag (ZMQ_CTX_TAG_VALUE_GOOD), tag (ZMQ_CTX_TAG_VALUE_GOOD),
starting (true), starting (true),
...@@ -45,7 +53,7 @@ zmq::ctx_t::ctx_t () : ...@@ -45,7 +53,7 @@ zmq::ctx_t::ctx_t () :
reaper (NULL), reaper (NULL),
slot_count (0), slot_count (0),
slots (NULL), slots (NULL),
max_sockets (ZMQ_MAX_SOCKETS_DFLT), max_sockets(clipped_maxsocket(ZMQ_MAX_SOCKETS_DFLT)),
io_thread_count (ZMQ_IO_THREADS_DFLT), io_thread_count (ZMQ_IO_THREADS_DFLT),
ipv6 (false) ipv6 (false)
{ {
...@@ -161,7 +169,7 @@ int zmq::ctx_t::shutdown () ...@@ -161,7 +169,7 @@ int zmq::ctx_t::shutdown ()
int zmq::ctx_t::set (int option_, int optval_) int zmq::ctx_t::set (int option_, int optval_)
{ {
int rc = 0; int rc = 0;
if (option_ == ZMQ_MAX_SOCKETS && optval_ >= 1) { if (option_ == ZMQ_MAX_SOCKETS && optval_ >= 1 && optval_ == clipped_maxsocket(optval_)) {
opt_sync.lock (); opt_sync.lock ();
max_sockets = optval_; max_sockets = optval_;
opt_sync.unlock (); opt_sync.unlock ();
......
...@@ -133,6 +133,11 @@ void zmq::devpoll_t::stop () ...@@ -133,6 +133,11 @@ void zmq::devpoll_t::stop ()
stopping = true; stopping = true;
} }
int zmq::devpoll_t::max_fds()
{
return -1;
}
void zmq::devpoll_t::loop () void zmq::devpoll_t::loop ()
{ {
while (!stopping) { while (!stopping) {
......
...@@ -56,6 +56,8 @@ namespace zmq ...@@ -56,6 +56,8 @@ namespace zmq
void start (); void start ();
void stop (); void stop ();
static int max_fds();
private: private:
// Main worker thread routine. // Main worker thread routine.
......
...@@ -126,6 +126,11 @@ void zmq::epoll_t::stop () ...@@ -126,6 +126,11 @@ void zmq::epoll_t::stop ()
stopping = true; stopping = true;
} }
int zmq::epoll_t::max_fds()
{
return -1;
}
void zmq::epoll_t::loop () void zmq::epoll_t::loop ()
{ {
epoll_event ev_buf [max_io_events]; epoll_event ev_buf [max_io_events];
......
...@@ -58,6 +58,8 @@ namespace zmq ...@@ -58,6 +58,8 @@ namespace zmq
void start (); void start ();
void stop (); void stop ();
static int max_fds();
private: private:
// Main worker thread routine. // Main worker thread routine.
......
...@@ -152,6 +152,11 @@ void zmq::kqueue_t::stop () ...@@ -152,6 +152,11 @@ void zmq::kqueue_t::stop ()
stopping = true; stopping = true;
} }
int zmq::kqueue_t::max_fds()
{
return -1;
}
void zmq::kqueue_t::loop () void zmq::kqueue_t::loop ()
{ {
while (!stopping) { while (!stopping) {
......
...@@ -58,6 +58,8 @@ namespace zmq ...@@ -58,6 +58,8 @@ namespace zmq
void start (); void start ();
void stop (); void stop ();
static int max_fds();
private: private:
// Main worker thread routine. // Main worker thread routine.
......
...@@ -114,6 +114,11 @@ void zmq::poll_t::stop () ...@@ -114,6 +114,11 @@ void zmq::poll_t::stop ()
stopping = true; stopping = true;
} }
int zmq::poll_t::max_fds()
{
return -1;
}
void zmq::poll_t::loop () void zmq::poll_t::loop ()
{ {
while (!stopping) { while (!stopping) {
......
...@@ -59,6 +59,8 @@ namespace zmq ...@@ -59,6 +59,8 @@ namespace zmq
void start (); void start ();
void stop (); void stop ();
static int max_fds();
private: private:
// Main worker thread routine. // Main worker thread routine.
......
...@@ -144,6 +144,11 @@ void zmq::select_t::stop () ...@@ -144,6 +144,11 @@ void zmq::select_t::stop ()
stopping = true; stopping = true;
} }
int zmq::select_t::max_fds()
{
return FD_SETSIZE;
}
void zmq::select_t::loop () void zmq::select_t::loop ()
{ {
while (!stopping) { while (!stopping) {
......
...@@ -69,6 +69,8 @@ namespace zmq ...@@ -69,6 +69,8 @@ namespace zmq
void start (); void start ();
void stop (); void stop ();
static int max_fds();
private: private:
// Main worker thread routine. // Main worker thread routine.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment