Wrapper class for polling ZeroMQ sockets.
This class simplifies calls to poll or ppoll ZeroMQ sockets. It stores the list of sockets to be polled, which means they don't have to be separately carried around by the user. It also parses output and returns an easily digestible vector of events.
Definition at line 26 of file ZeroMQPoller.h.
Public Types | |
using | entry_t = std::tuple< size_t, zmq::event_flags, const zmq::socket_t * > |
using | fd_entry_t = std::tuple< size_t, zmq::event_flags > |
using | fds_t = std::unordered_map< int, fd_entry_t > |
using | free_t = std::deque< int > |
using | sockets_t = std::unordered_map< void *, entry_t > |
Public Member Functions | |
ZeroMQPoller ()=default | |
std::vector< std::pair< size_t, zmq::event_flags > > | poll (int timeo=-1) |
Poll the sockets. | |
std::vector< std::pair< size_t, zmq::event_flags > > | ppoll (int timeo, const sigset_t *sigmask) |
Poll the sockets with ppoll. | |
size_t | register_socket (int fd, zmq::event_flags type) |
Register socket to poll. | |
size_t | register_socket (zmq::socket_t &socket, zmq::event_flags type) |
Register socket to poll. | |
size_t | size () const |
size_t | unregister_socket (int fd) |
Unregister socket from poller. | |
size_t | unregister_socket (zmq::socket_t &socket) |
Unregister socket from poller. | |
Private Attributes | |
fds_t | m_fds |
free_t | m_free |
std::vector< zmq::pollitem_t > | m_items |
sockets_t | m_sockets |
using ZeroMQPoller::entry_t = std::tuple<size_t, zmq::event_flags, const zmq::socket_t *> |
Definition at line 28 of file ZeroMQPoller.h.
using ZeroMQPoller::fd_entry_t = std::tuple<size_t, zmq::event_flags> |
Definition at line 33 of file ZeroMQPoller.h.
using ZeroMQPoller::fds_t = std::unordered_map<int, fd_entry_t> |
Definition at line 34 of file ZeroMQPoller.h.
using ZeroMQPoller::free_t = std::deque<int> |
Definition at line 36 of file ZeroMQPoller.h.
using ZeroMQPoller::sockets_t = std::unordered_map<void *, entry_t> |
Definition at line 31 of file ZeroMQPoller.h.
|
default |
std::vector< std::pair< size_t, zmq::event_flags > > ZeroMQPoller::poll | ( | int | timeo = -1 | ) |
Poll the sockets.
[in] | timeo | Timeout in milliseconds. 0 means return immediately. -1 means wait for an event indefinitely. |
Definition at line 37 of file ZeroMQPoller.cpp.
std::vector< std::pair< size_t, zmq::event_flags > > ZeroMQPoller::ppoll | ( | int | timeo, |
const sigset_t * | sigmask | ||
) |
Poll the sockets with ppoll.
By polling with ppoll instead of poll, one can pass along a signal mask to handle POSIX signals properly. See the zmq_ppoll documentation for examples of when this is useful: http://api.zeromq.org/
[in] | timeo | Timeout in milliseconds. 0 means return immediately. -1 means wait for an event indefinitely. |
[in] | sigmask | A non-nullptr pointer to a signal mask must be constructed and passed to 'sigmask'. See the man page of sigprocmask(2) for more details on this. |
Definition at line 91 of file ZeroMQPoller.cpp.
size_t ZeroMQPoller::register_socket | ( | int | fd, |
zmq::event_flags | type | ||
) |
Register socket to poll.
Adds the socket to the internal list of sockets to poll.
[in] | fd | File descriptor of socket to register. |
[in] | type | Type of events to poll for. Can be ZMQ_POLLIN, ZMQ_POLLOUT or a bit-wise combination of the two. |
Definition at line 165 of file ZeroMQPoller.cpp.
size_t ZeroMQPoller::register_socket | ( | zmq::socket_t & | socket, |
zmq::event_flags | type | ||
) |
Register socket to poll.
Adds the socket to the internal list of sockets to poll.
[in] | socket | Socket to register. |
[in] | type | Type of events to poll for. Can be ZMQ_POLLIN, ZMQ_POLLOUT or a bit-wise combination of the two. |
Definition at line 136 of file ZeroMQPoller.cpp.
size_t ZeroMQPoller::size | ( | ) | const |
Definition at line 121 of file ZeroMQPoller.cpp.
size_t ZeroMQPoller::unregister_socket | ( | int | fd | ) |
Unregister socket from poller.
Removes the socket from the internal list of sockets to poll.
[in] | fd | File descriptor of socket to unregister. |
Definition at line 225 of file ZeroMQPoller.cpp.
size_t ZeroMQPoller::unregister_socket | ( | zmq::socket_t & | socket | ) |
Unregister socket from poller.
Removes the socket from the internal list of sockets to poll.
[in] | socket | Socket to unregister. |
Definition at line 191 of file ZeroMQPoller.cpp.
|
private |
Definition at line 55 of file ZeroMQPoller.h.
|
private |
Definition at line 58 of file ZeroMQPoller.h.
|
private |
Definition at line 53 of file ZeroMQPoller.h.
|
private |
Definition at line 54 of file ZeroMQPoller.h.