|
CppZmqZoltanExt 0.0.1
|
Class for efficient polling of multiple ZMQ sockets. More...
#include <poller.h>
Public Member Functions | |
| void | add (zmq::socket_ref socket) |
| Add a socket to the polling set. | |
| void | remove (zmq::socket_ref socket) |
| Remove a socket from the polling set. | |
| void | set_interruptible (bool interruptible) noexcept |
| Set whether polling should be interruptible. | |
| bool | is_interruptible () const noexcept |
| Check if polling is interruptible. | |
| std::size_t | size () const noexcept |
| Get the number of sockets in the polling set. | |
| bool | terminated () const noexcept |
| Check if the poller has been terminated during the last wait operation. | |
| zmq::socket_ref | wait (std::chrono::milliseconds timeout=std::chrono::milliseconds{-1}) |
| Wait for any socket to become ready for receiving. | |
| std::vector< zmq::socket_ref > | wait_all (std::chrono::milliseconds timeout=std::chrono::milliseconds{-1}) |
| Wait for at least one socket to become ready for receiving and return all ready. | |
Class for efficient polling of multiple ZMQ sockets.
The poller_t class provides a convenient wrapper around ZMQ's polling mechanism. It allows applications to monitor multiple sockets simultaneously and wait for data availability on any or all of them.
The poller supports adding and removing sockets to be monitored at any time.
When used in conjunction with the interrupt handling module and the application receives a SIINT or SIGTERM signal, the poller will return early from wait operations, allowing the application to handle the interrupt by checking if the poller was terminated.
The set_interruptible() method can be used to enable or disable interrupt checking. When set to false (the default is true), the poller will still return early on interrupt signals, but the terminated() method will always return false. This behavior may be desirable on actors when they should continue processing all events before receiving a stop request from the main application. So the main application can perform a graceful shutdown without the actors loosing any messages that are already in their queues.
| void zmqzext::poller_t::add | ( | zmq::socket_ref | socket | ) |
Add a socket to the polling set.
Registers a socket with the poller for monitoring. The socket will be polled in subsequent wait operations to detect readiness for receive operation.
| socket | The ZMQ socket reference to add |
| std::invalid_argument | if the socket is invalid or already added |
Definition at line 45 of file poller.cpp.
|
inlinenoexcept |
Check if polling is interruptible.
| void zmqzext::poller_t::remove | ( | zmq::socket_ref | socket | ) |
Remove a socket from the polling set.
Unregisters a socket from the poller. The socket will no longer be monitored in wait operations.
| socket | The ZMQ socket reference to remove |
Definition at line 57 of file poller.cpp.
|
inlinenoexcept |
Set whether polling should be interruptible.
Controls whether the poller will check for interrupt signals during wait operations.
When enabled (default), the poller wait operations will return immediately if an interrupt signal was already received, or return early if an interrupt signal is received during the wait operations. The is_terminated() will then return true.
When interruptible is disabled, the wait operations are allowed to wait for incoming messages in the monitored sockets even if an interrupt signal was already received. Still, the wait operations will return early if an interrupt signal is received during the wait. The is_terminated() method will always return false, even if an interrupt signal was received. This behavior may be desirable on actors when they should continue processing all events before receiving a stop request from the main application. So the main application can perform a graceful shutdown without the actors loosing any messages that are already in their queues.
| interruptible | true to enable interrupt checking, false otherwise |
|
inlinenoexcept |
|
inlinenoexcept |
Check if the poller has been terminated during the last wait operation.
Returns whether a termination condition has been detected during the last wait operation. The termination condition occurs when an interrupt signal is received and the poller is interruptible or when the context associated with any of the monitored sockets is terminated.
The terminated state is reset on each wait operation so a new wait can be performed after receiving an interrupt signal when the interruptible mode is disabled.
| zmq::socket_ref zmqzext::poller_t::wait | ( | std::chrono::milliseconds | timeout = std::chrono::milliseconds{-1} | ) |
Wait for any socket to become ready for receiving.
Blocks until at least one socket becomes ready for receiving, the timeout expires, an interrupt signal is received or the context associated with any of the monitored sockets is terminated. Returns the first ready socket found.
Sockets are checked in the order they were added to the poller. If multiple sockets are ready, the first one is returned. If the same socket is always ready, it may starve other sockets. For fairness, consider using wait_all() instead.
| timeout | Maximum wait duration in milliseconds (default: -1 for infinite timeout) |
| zmq::error_t | if a ZMQ error occurs |
Definition at line 64 of file poller.cpp.
| std::vector< zmq::socket_ref > zmqzext::poller_t::wait_all | ( | std::chrono::milliseconds | timeout = std::chrono::milliseconds{-1} | ) |
Wait for at least one socket to become ready for receiving and return all ready.
Blocks until at least one socket becomes ready for receiving, the timeout expires, an interrupt signal is received or the context associated with any of the monitored sockets is terminated. Returns all ready sockets at the time of the check.
Sockets are checked in the order they were added to the poller. If multiple sockets are ready, all of them are returned in the order they were added.
| timeout | Maximum wait duration in milliseconds (default: -1 for infinite timeout) |
| zmq::error_t | if a ZMQ error occurs |
Definition at line 101 of file poller.cpp.