Skip to content

Commit

Permalink
Merge pull request #622 from typon/typon/generic-poller-events
Browse files Browse the repository at this point in the history
allow generic sequence of poller events
  • Loading branch information
gummif authored Oct 30, 2023
2 parents 160ac8e + 3f6fe44 commit 6164cf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> poller;
std::array<zmq::poller_event<int>, 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;
Expand Down
6 changes: 5 additions & 1 deletion zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#include <cassert>
#include <cstring>

#include <type_traits>
#include <algorithm>
#include <exception>
#include <iomanip>
Expand Down Expand Up @@ -2714,9 +2715,12 @@ template<typename T = no_user_data> class poller_t
}
}

size_t wait_all(std::vector<event_type> &poller_events,
template <typename Sequence>
size_t wait_all(Sequence &poller_events,
const std::chrono::milliseconds timeout)
{
static_assert(std::is_same<typename Sequence::value_type, event_type>::value,
"Sequence::value_type must be of poller_t::event_type");
int rc = zmq_poller_wait_all(
poller_ptr.get(),
reinterpret_cast<zmq_poller_event_t *>(poller_events.data()),
Expand Down

0 comments on commit 6164cf7

Please sign in to comment.