mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-31 01:43:02 +08:00
Merge pull request #745 from ricnewton/master
Get maximum number of sockets it can handle from poller_t
This commit is contained in:
commit
4616403b10
12
src/ctx.cpp
12
src/ctx.cpp
@ -38,6 +38,14 @@
|
||||
#define ZMQ_CTX_TAG_VALUE_GOOD 0xabadcafe
|
||||
#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 () :
|
||||
tag (ZMQ_CTX_TAG_VALUE_GOOD),
|
||||
starting (true),
|
||||
@ -45,7 +53,7 @@ zmq::ctx_t::ctx_t () :
|
||||
reaper (NULL),
|
||||
slot_count (0),
|
||||
slots (NULL),
|
||||
max_sockets (ZMQ_MAX_SOCKETS_DFLT),
|
||||
max_sockets (clipped_maxsocket (ZMQ_MAX_SOCKETS_DFLT)),
|
||||
io_thread_count (ZMQ_IO_THREADS_DFLT),
|
||||
ipv6 (false)
|
||||
{
|
||||
@ -161,7 +169,7 @@ int zmq::ctx_t::shutdown ()
|
||||
int zmq::ctx_t::set (int option_, int optval_)
|
||||
{
|
||||
int rc = 0;
|
||||
if (option_ == ZMQ_MAX_SOCKETS && optval_ >= 1) {
|
||||
if (option_ == ZMQ_MAX_SOCKETS && optval_ >= 1 && optval_ == clipped_maxsocket (optval_)) {
|
||||
opt_sync.lock ();
|
||||
max_sockets = optval_;
|
||||
opt_sync.unlock ();
|
||||
|
@ -133,6 +133,11 @@ void zmq::devpoll_t::stop ()
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
int zmq::devpoll_t::max_fds ()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void zmq::devpoll_t::loop ()
|
||||
{
|
||||
while (!stopping) {
|
||||
|
@ -56,6 +56,8 @@ namespace zmq
|
||||
void start ();
|
||||
void stop ();
|
||||
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
|
@ -126,6 +126,11 @@ void zmq::epoll_t::stop ()
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
int zmq::epoll_t::max_fds ()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void zmq::epoll_t::loop ()
|
||||
{
|
||||
epoll_event ev_buf [max_io_events];
|
||||
|
@ -58,6 +58,8 @@ namespace zmq
|
||||
void start ();
|
||||
void stop ();
|
||||
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
|
@ -152,6 +152,11 @@ void zmq::kqueue_t::stop ()
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
int zmq::kqueue_t::max_fds ()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void zmq::kqueue_t::loop ()
|
||||
{
|
||||
while (!stopping) {
|
||||
|
@ -58,6 +58,8 @@ namespace zmq
|
||||
void start ();
|
||||
void stop ();
|
||||
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
|
@ -114,6 +114,11 @@ void zmq::poll_t::stop ()
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
int zmq::poll_t::max_fds ()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void zmq::poll_t::loop ()
|
||||
{
|
||||
while (!stopping) {
|
||||
|
@ -59,6 +59,8 @@ namespace zmq
|
||||
void start ();
|
||||
void stop ();
|
||||
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
|
@ -144,6 +144,11 @@ void zmq::select_t::stop ()
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
int zmq::select_t::max_fds ()
|
||||
{
|
||||
return FD_SETSIZE;
|
||||
}
|
||||
|
||||
void zmq::select_t::loop ()
|
||||
{
|
||||
while (!stopping) {
|
||||
|
@ -69,6 +69,8 @@ namespace zmq
|
||||
void start ();
|
||||
void stop ();
|
||||
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
|
Loading…
x
Reference in New Issue
Block a user