zmqpp
4.1.2
C++ bindings for 0mq (libzmq)
|
Polling wrapper. More...
#include <poller.hpp>
Public Member Functions | |
poller () | |
Construct an empty polling model. More... | |
~poller () | |
Cleanup poller. More... | |
void | add (socket_t &socket, short const event=poll_in) |
Add a socket to the polling model and set which events to monitor. More... | |
void | add (raw_socket_t const descriptor, short const event=poll_in|poll_error) |
Add a standard socket to the polling model and set which events to monitor. More... | |
void | add (zmq_pollitem_t const &item) |
Add a zmq_pollitem_t to the poller; Events to monitor are already configured. More... | |
bool | has (socket_t const &socket) |
Check if we are monitoring a given socket with this poller. More... | |
bool | has (raw_socket_t const descriptor) |
Check if we are monitoring a given standard socket with this poller. More... | |
bool | has (zmq_pollitem_t const &item) |
Check if we are monitoring a given pollitem. More... | |
void | remove (socket_t const &socket) |
Stop monitoring a socket. More... | |
void | remove (raw_socket_t const descriptor) |
Stop monitoring a standard socket. More... | |
void | remove (zmq_pollitem_t const &item) |
Stop monitoring a zmq_pollitem_t. More... | |
void | check_for (socket_t const &socket, short const event) |
Update the monitored event flags for a given socket. More... | |
void | check_for (raw_socket_t const descriptor, short const event) |
void | check_for (zmq_pollitem_t const &item, short const event) |
Update the monitored event flags for a given zmq_pollitem_t. More... | |
bool | poll (long timeout=wait_forever) |
Poll for monitored events. More... | |
short | events (socket_t const &socket) const |
Get the event flags triggered for a socket. More... | |
short | events (raw_socket_t const descriptor) const |
Get the event flags triggered for a standard socket. More... | |
short | events (zmq_pollitem_t const &item) const |
Get the event flags triggered for a zmq_pollitem_t. More... | |
template<typename Watched > | |
bool | has_input (Watched const &watchable) const |
Check either a standard socket or zmq socket for input events. More... | |
template<typename Watched > | |
bool | has_output (Watched const &watchable) const |
Check either a standard socket or zmq socket for output events. More... | |
template<typename Watched > | |
bool | has_error (Watched const &watchable) const |
Check a standard socket (file descriptor or SOCKET). More... | |
Static Public Attributes | |
static const long | wait_forever = -1 |
static const short | poll_none = 0 |
static const short | poll_in = ZMQ_POLLIN |
static const short | poll_out = ZMQ_POLLOUT |
static const short | poll_error = ZMQ_POLLERR |
static const short | poll_pri = ZMQ_POLLPRI |
Private Member Functions | |
void | reindex (size_t const index) |
Private Attributes | |
std::vector< zmq_pollitem_t > | _items |
std::unordered_map< void *, size_t > | _index |
std::unordered_map < raw_socket_t, size_t > | _fdindex |
Polling wrapper.
Allows access to polling for any number of zmq sockets or standard sockets.
zmqpp::poller::poller | ( | ) |
Construct an empty polling model.
zmqpp::poller::~poller | ( | ) |
Cleanup poller.
Any sockets will need to be closed separately.
Add a socket to the polling model and set which events to monitor.
socket | the socket to monitor. |
event | the event flags to monitor on the socket. |
void zmqpp::poller::add | ( | raw_socket_t const | descriptor, |
short const | event = poll_in | poll_error |
||
) |
Add a standard socket to the polling model and set which events to monitor.
descriptor | the raw socket to monitor (SOCKET under Windows, a file descriptor otherwise). |
event | the event flags to monitor. |
void zmqpp::poller::add | ( | zmq_pollitem_t const & | item | ) |
Add a zmq_pollitem_t to the poller; Events to monitor are already configured.
If the zmq_pollitem_t has a null socket pointer it is added to the fdindex, otherwise it is added to the socket index.
item | the pollitem to be added |
void zmqpp::poller::check_for | ( | socket_t const & | socket, |
short const | event | ||
) |
Update the monitored event flags for a given socket.
socket | the socket to update event flags. |
event | the event flags to monitor on the socket. |
void zmqpp::poller::check_for | ( | raw_socket_t const | descriptor, |
short const | event | ||
) |
Update the monitored event flags for a given standard socket.
descriptor | the raw socket to update event flags (SOCKET under Windows, a file descriptor otherwise). |
event | the event flags to monitor on the socket. |
void zmqpp::poller::check_for | ( | zmq_pollitem_t const & | item, |
short const | event | ||
) |
Update the monitored event flags for a given zmq_pollitem_t.
item | the item to change event flags for. |
event | the event flags to monitor on the socket. |
short zmqpp::poller::events | ( | socket_t const & | socket | ) | const |
Get the event flags triggered for a socket.
socket | the socket to get triggered event flags for. |
short zmqpp::poller::events | ( | raw_socket_t const | descriptor | ) | const |
Get the event flags triggered for a standard socket.
descriptor | the raw socket to get triggered event flags for (SOCKET under Windows, a file descriptor otherwise). |
short zmqpp::poller::events | ( | zmq_pollitem_t const & | item | ) | const |
Get the event flags triggered for a zmq_pollitem_t.
item | the pollitem to get triggered event flags for. |
bool zmqpp::poller::has | ( | socket_t const & | socket | ) |
Check if we are monitoring a given socket with this poller.
socket | the socket to check. |
bool zmqpp::poller::has | ( | raw_socket_t const | descriptor | ) |
Check if we are monitoring a given standard socket with this poller.
descriptor | the raw socket to check for. |
bool zmqpp::poller::has | ( | zmq_pollitem_t const & | item | ) |
Check if we are monitoring a given pollitem.
We assume the pollitem is a socket if it's socket is a non null pointer; otherwise, it is considered as a file descriptor.
item | the pollitem to check for |
|
inline |
Check a standard socket (file descriptor or SOCKET).
Templated helper method that calls through to event and checks for a given flag
Technically this template works for sockets as well but the error flag is never set for sockets so I have no idea why someone would call it.
watchable | a standard socket known to the poller. |
|
inline |
Check either a standard socket or zmq socket for input events.
Templated helper method that calls through to event and checks for a given flag
watchable | either a standard socket or socket known to the poller. |
|
inline |
Check either a standard socket or zmq socket for output events.
Templated helper method that calls through to event and checks for a given flag
watchable | either a standard socket or zmq socket known to the poller. |
bool zmqpp::poller::poll | ( | long | timeout = wait_forever | ) |
Poll for monitored events.
By default this method will block forever or until at least one of the monitored sockets or file descriptors has events.
If a timeout is set and was reached then this function returns false.
timeout | milliseconds to timeout. |
|
private |
void zmqpp::poller::remove | ( | socket_t const & | socket | ) |
Stop monitoring a socket.
socket | the socket to stop monitoring. |
void zmqpp::poller::remove | ( | raw_socket_t const | descriptor | ) |
Stop monitoring a standard socket.
descriptor | the raw socket to stop monitoring (SOCKET under Windows, a file descriptor otherwise). |
void zmqpp::poller::remove | ( | zmq_pollitem_t const & | item | ) |
Stop monitoring a zmq_pollitem_t.
item | the pollitem to stop monitoring. |
|
private |
|
private |
|
private |
|
static |
Monitor error flag.
Only for file descriptors.
|
static |
Monitor inbound flag.
|
static |
No polling flags set.
|
static |
Monitor output flag.
|
static |
Priority input flag.
Only for file descriptors. See POLLPRI)
|
static |
Block forever flag, default setting.