Skip to content

Commit 2af0c01

Browse files
committed
Problem: Poller size function missing
Solution: Add it to poller_t
1 parent 03243ad commit 2af0c01

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
@@ -2653,6 +2653,15 @@ template<typename T = no_user_data> class poller_t
26532653
throw error_t();
26542654
}
26552655

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

0 commit comments

Comments
 (0)