Skip to content

Commit 18db456

Browse files
authored
Merge pull request #451 from gummif/gfa/poller-size
Problem: Poller size function missing
2 parents 05ff657 + 2af0c01 commit 18db456

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/poller.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ TEST_CASE("poller wait with no handlers throws", "[poller]")
133133
const zmq::error_t&);
134134
}
135135

136+
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3)
137+
TEST_CASE("poller add/remove size checks", "[poller]")
138+
{
139+
zmq::context_t context;
140+
zmq::socket_t socket{context, zmq::socket_type::router};
141+
zmq::poller_t<> poller;
142+
CHECK(poller.size() == 0);
143+
poller.add(socket, zmq::event_flags::pollin);
144+
CHECK(poller.size() == 1);
145+
CHECK_NOTHROW(poller.remove(socket));
146+
CHECK(poller.size() == 0);
147+
}
148+
#endif
149+
136150
TEST_CASE("poller remove unregistered throws", "[poller]")
137151
{
138152
zmq::context_t context;

zmq.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,15 @@ template<typename T = no_user_data> class poller_t
26542654
throw error_t();
26552655
}
26562656

2657+
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3)
2658+
size_t size() const noexcept
2659+
{
2660+
int rc = zmq_poller_size(const_cast<void *>(poller_ptr.get()));
2661+
ZMQ_ASSERT(rc >= 0);
2662+
return static_cast<size_t>(std::max(rc, 0));
2663+
}
2664+
#endif
2665+
26572666
private:
26582667
struct destroy_poller_t
26592668
{

0 commit comments

Comments
 (0)