From 3f6fe441e4234d1a703990f84646be3ea26f29dd Mon Sep 17 00:00:00 2001 From: hfarooq Date: Thu, 26 Oct 2023 22:03:37 +0000 Subject: [PATCH] allow generic sequence of poller events --- tests/poller.cpp | 15 +++++++++++++++ zmq.hpp | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/poller.cpp b/tests/poller.cpp index 81c42e6..174270b 100644 --- a/tests/poller.cpp +++ b/tests/poller.cpp @@ -192,6 +192,21 @@ TEST_CASE("poller poll basic", "[poller]") CHECK(&i == events[0].user_data); } +TEST_CASE("poller poll basic static array", "[poller]") +{ + common_server_client_setup s; + + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); + + zmq::poller_t poller; + std::array, 1> events; + int i = 0; + CHECK_NOTHROW(poller.add(s.server, zmq::event_flags::pollin, &i)); + CHECK(1 == poller.wait_all(events, std::chrono::milliseconds{-1})); + CHECK(s.server == events[0].socket); + CHECK(&i == events[0].user_data); +} + TEST_CASE("poller add invalid socket throws", "[poller]") { zmq::context_t context; diff --git a/zmq.hpp b/zmq.hpp index 987d7ef..29ac435 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -108,6 +108,7 @@ #include #include +#include #include #include #include @@ -2714,9 +2715,12 @@ template class poller_t } } - size_t wait_all(std::vector &poller_events, + template + size_t wait_all(Sequence &poller_events, const std::chrono::milliseconds timeout) { + static_assert(std::is_same::value, + "Sequence::value_type must be of poller_t::event_type"); int rc = zmq_poller_wait_all( poller_ptr.get(), reinterpret_cast(poller_events.data()),