From 2af0c0105a2bcb836cc37d29fce710b80dec4c18 Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Sat, 10 Oct 2020 21:22:16 +0000 Subject: [PATCH] Problem: Poller size function missing Solution: Add it to poller_t --- tests/poller.cpp | 14 ++++++++++++++ zmq.hpp | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/poller.cpp b/tests/poller.cpp index 72443575..55d85ce8 100644 --- a/tests/poller.cpp +++ b/tests/poller.cpp @@ -133,6 +133,20 @@ TEST_CASE("poller wait with no handlers throws", "[poller]") const zmq::error_t&); } +#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3) +TEST_CASE("poller add/remove size checks", "[poller]") +{ + zmq::context_t context; + zmq::socket_t socket{context, zmq::socket_type::router}; + zmq::poller_t<> poller; + CHECK(poller.size() == 0); + poller.add(socket, zmq::event_flags::pollin); + CHECK(poller.size() == 1); + CHECK_NOTHROW(poller.remove(socket)); + CHECK(poller.size() == 0); +} +#endif + TEST_CASE("poller remove unregistered throws", "[poller]") { zmq::context_t context; diff --git a/zmq.hpp b/zmq.hpp index fac00fc6..3bdcfda7 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -2653,6 +2653,15 @@ template class poller_t throw error_t(); } +#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3) + size_t size() const noexcept + { + int rc = zmq_poller_size(const_cast(poller_ptr.get())); + ZMQ_ASSERT(rc >= 0); + return static_cast(std::max(rc, 0)); + } +#endif + private: struct destroy_poller_t {