zmqpp
4.1.2
C++ bindings for 0mq (libzmq)
|
Reactor object that helps to manage multiple socket by calling a user-defined handler for each socket when a watched event occurs. More...
#include <reactor.hpp>
Public Types | |
typedef std::function< void(void) > | Callable |
typedef std::pair < zmq_pollitem_t, Callable > | PollItemCallablePair |
Public Member Functions | |
reactor () | |
Construct an empty polling model. More... | |
~reactor () | |
Cleanup reactor. More... | |
void | add (socket_t &socket, Callable callable, short const event=poller::poll_in) |
Add a socket to the reactor, providing a handler that will be called when the monitored events occur. More... | |
void | add (raw_socket_t const descriptor, Callable callable, short const event=poller::poll_in|poller::poll_error) |
bool | has (socket_t const &socket) |
Check if we are monitoring a given socket with this reactor. More... | |
bool | has (raw_socket_t const descriptor) |
Check if we are monitoring a given standard socket with this reactor. 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 | 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) |
bool | poll (long timeout=poller::wait_forever) |
Poll for monitored events and call associated handler when needed. 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... | |
poller & | get_poller () |
Get a reference to the underlying poller object used by the reactor. More... | |
const poller & | get_poller () const |
Get a reference to the underlying poller object used by the reactor (const version). More... | |
Protected Member Functions | |
void | add (const zmq_pollitem_t &item, Callable callable) |
Private Member Functions | |
void | flush_remove_later () |
Flush the fdRemoveLater_ and sockRemoveLater_ vector, effectively removing the item for the reactor and poller. More... | |
Private Attributes | |
std::vector< PollItemCallablePair > | items_ |
std::vector< const socket_t * > | sockRemoveLater_ |
std::vector< raw_socket_t > | fdRemoveLater_ |
poller | poller_ |
bool | dispatching_ |
Reactor object that helps to manage multiple socket by calling a user-defined handler for each socket when a watched event occurs.
It uses zmq::poller as the underlying polling mechanism.
typedef std::function<void (void) > zmqpp::reactor::Callable |
typedef std::pair<zmq_pollitem_t, Callable> zmqpp::reactor::PollItemCallablePair |
zmqpp::reactor::reactor | ( | ) |
Construct an empty polling model.
zmqpp::reactor::~reactor | ( | ) |
Cleanup reactor.
Any sockets will need to be closed separately.
void zmqpp::reactor::add | ( | socket_t & | socket, |
Callable | callable, | ||
short const | event = poller::poll_in |
||
) |
Add a socket to the reactor, providing a handler that will be called when the monitored events occur.
socket | the socket to monitor. |
callable | the function that will be called by the reactor when a registered event occurs on socket. |
event | the event flags to monitor on the socket. |
void zmqpp::reactor::add | ( | raw_socket_t const | descriptor, |
Callable | callable, | ||
short const | event = poller::poll_in | poller::poll_error |
||
) |
Add a standard socket to the reactor, providing a handler that will be called when the monitored events occur.
descriptor | the standard socket to monitor (SOCKET under Windows, a file descriptor otherwise). |
callable | the function that will be called by the reactor when a registered event occurs on fd. |
event | the event flags to monitor. |
|
protected |
void zmqpp::reactor::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::reactor::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. |
short zmqpp::reactor::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::reactor::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). |
|
private |
Flush the fdRemoveLater_ and sockRemoveLater_ vector, effectively removing the item for the reactor and poller.
poller & zmqpp::reactor::get_poller | ( | ) |
Get a reference to the underlying poller object used by the reactor.
Not sure this is useful.
const poller & zmqpp::reactor::get_poller | ( | ) | const |
Get a reference to the underlying poller object used by the reactor (const version).
Not sure this is useful either.
bool zmqpp::reactor::has | ( | socket_t const & | socket | ) |
Check if we are monitoring a given socket with this reactor.
socket | the socket to check. |
bool zmqpp::reactor::has | ( | raw_socket_t const | descriptor | ) |
Check if we are monitoring a given standard socket with this reactor.
descriptor | the raw socket to check (SOCKET under Windows, a file descriptor otherwise). |
bool zmqpp::reactor::poll | ( | long | timeout = poller::wait_forever | ) |
Poll for monitored events and call associated handler when needed.
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. |
void zmqpp::reactor::remove | ( | socket_t const & | socket | ) |
Stop monitoring a socket.
socket | the socket to stop monitoring. |
void zmqpp::reactor::remove | ( | raw_socket_t const | descriptor | ) |
Stop monitoring a standard socket.
descriptor | the standard socket to stop monitoring. |
|
private |
|
private |
|
private |
|
private |
|
private |