27bool ZMQConnection::poll(
const std::map<const ZMQConnection*, ZMQConnection::ReactorFunction>& connectionList,
int timeout)
29 std::vector<const ReactorFunction*> socketMapping;
30 std::vector<zmq::pollitem_t> pollItems;
33 for (
const auto& [connection, function] : connectionList) {
34 auto sockets = connection->getSockets();
35 for (zmq::socket_t* socket : sockets) {
36 zmq::pollitem_t pollItem;
37 pollItem.socket =
static_cast<void*
>(*socket);
38 pollItem.events = ZMQ_POLLIN;
40 pollItems.push_back(std::move(pollItem));
43 socketMapping.push_back(&function);
47 if (pollItems.empty()) {
52 zmq::poll(&pollItems[0], pollItems.size(), timeout);
54 bool anySocket =
false;
55 unsigned int counter = 0;
56 for (
const auto& pollItem : pollItems) {
57 if (pollItem.revents & ZMQ_POLLIN) {
59 const auto* functionPtr = socketMapping.at(counter);
60 const auto function = *functionPtr;
67 }
catch (zmq::error_t& error) {
68 if (error.num() == EINTR) {
static bool poll(const std::map< const ZMQConnection *, ReactorFunction > &connectionList, int timeout)
Poll on the given connections and call the attached function if a messages comes in.