Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f6fe44

Browse files
committed
allow generic sequence of poller events
1 parent 160ac8e commit 3f6fe44

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎tests/poller.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ TEST_CASE("poller poll basic", "[poller]")
192192
CHECK(&i == events[0].user_data);
193193
}
194194

195+
TEST_CASE("poller poll basic static array", "[poller]")
196+
{
197+
common_server_client_setup s;
198+
199+
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
200+
201+
zmq::poller_t<int> poller;
202+
std::array<zmq::poller_event<int>, 1> events;
203+
int i = 0;
204+
CHECK_NOTHROW(poller.add(s.server, zmq::event_flags::pollin, &i));
205+
CHECK(1 == poller.wait_all(events, std::chrono::milliseconds{-1}));
206+
CHECK(s.server == events[0].socket);
207+
CHECK(&i == events[0].user_data);
208+
}
209+
195210
TEST_CASE("poller add invalid socket throws", "[poller]")
196211
{
197212
zmq::context_t context;

‎zmq.hpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#include <cassert>
109109
#include <cstring>
110110

111+
#include <type_traits>
111112
#include <algorithm>
112113
#include <exception>
113114
#include <iomanip>
@@ -2714,9 +2715,12 @@ template<typename T = no_user_data> class poller_t
27142715
}
27152716
}
27162717

2717-
size_t wait_all(std::vector<event_type> &poller_events,
2718+
template <typename Sequence>
2719+
size_t wait_all(Sequence &poller_events,
27182720
const std::chrono::milliseconds timeout)
27192721
{
2722+
static_assert(std::is_same<typename Sequence::value_type, event_type>::value,
2723+
"Sequence::value_type must be of poller_t::event_type");
27202724
int rc = zmq_poller_wait_all(
27212725
poller_ptr.get(),
27222726
reinterpret_cast<zmq_poller_event_t *>(poller_events.data()),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /