CppZmqZoltanExt 0.0.1
Loading...
Searching...
No Matches
poller.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 Luan Young
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
54#pragma once
55
56#include <chrono>
57#include <vector>
58#include <zmq.hpp>
59
60#include "cppzmqzoltanext/czze_export.h"
61
62namespace zmqzext {
63
91class CZZE_EXPORT poller_t {
92public:
103 void add(zmq::socket_ref socket);
104
115 void remove(zmq::socket_ref socket);
116
142 void set_interruptible(bool interruptible) noexcept { _interruptible = interruptible; }
143
150 bool is_interruptible() const noexcept { return _interruptible; }
151
157 std::size_t size() const noexcept { return _poll_items.size(); }
158
174 bool terminated() const noexcept { return _terminated; }
175
196 zmq::socket_ref wait(std::chrono::milliseconds timeout = std::chrono::milliseconds{-1});
197
216 std::vector<zmq::socket_ref> wait_all(std::chrono::milliseconds timeout = std::chrono::milliseconds{-1});
217
218private:
225 bool has_socket(void* socket_handle) const;
226
227private:
228 std::vector<zmq::pollitem_t> _poll_items;
229 bool _interruptible{true};
230 bool _terminated{false};
231};
232
233} // namespace zmqzext
Class for efficient polling of multiple ZMQ sockets.
Definition: poller.h:91
bool is_interruptible() const noexcept
Check if polling is interruptible.
Definition: poller.h:150
void set_interruptible(bool interruptible) noexcept
Set whether polling should be interruptible.
Definition: poller.h:142
std::size_t size() const noexcept
Get the number of sockets in the polling set.
Definition: poller.h:157
bool terminated() const noexcept
Check if the poller has been terminated during the last wait operation.
Definition: poller.h:174