mirror of
https://github.com/zeromq/cppzmq.git
synced 2024-12-12 10:33:52 +01:00
allow generic sequence of poller events
This commit is contained in:
parent
160ac8ec61
commit
3f6fe441e4
@ -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;
|
||||
|
6
zmq.hpp
6
zmq.hpp
@ -108,6 +108,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <iomanip>
|
||||
@ -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()),
|
||||
|
Loading…
Reference in New Issue
Block a user