zmqpp 4.1.2
C++ bindings for 0mq (libzmq)
|
Loop object that helps to manage multiple socket by calling a user-defined handler for each socket when a watched event occurs. More...
#include <loop.hpp>
Classes | |
struct | timer_t |
Public Types | |
typedef void * | timer_id_t |
Type used to identify created timers withing loop. | |
typedef std::function< bool(void) > | Callable |
Public Member Functions | |
loop () | |
Construct an empty polling model. | |
virtual | ~loop () |
Cleanup reactor. | |
void | add (socket_t &socket, Callable callable, short const event=poller::poll_in) |
Add a socket to the loop, providing a handler that will be called when the monitored events occur. | |
void | add (raw_socket_t const descriptor, Callable callable, short const event=poller::poll_in|poller::poll_error) |
timer_id_t | add (std::chrono::milliseconds delay, size_t times, Callable callable) |
Add a timed event to the loop, providing a handler that will be called when timer fires. | |
void | reset (timer_id_t const timer) |
Reset timer in the loop, it will start counting delay time again. | |
void | remove (timer_id_t const timer) |
Remove timer event from the loop. | |
void | remove (socket_t const &socket) |
Stop monitoring a socket. | |
void | remove (raw_socket_t const descriptor) |
Stop monitoring a standard socket. | |
void | start () |
Starts loop. | |
Private Types | |
typedef std::pair< zmq_pollitem_t, Callable > | PollItemCallablePair |
typedef std::pair< std::unique_ptr< timer_t >, Callable > | TimerItemCallablePair |
Private Member Functions | |
void | add (const zmq_pollitem_t &item, Callable callable) |
void | add (std::unique_ptr< timer_t >, Callable callable) |
bool | start_handle_timers () |
bool | start_handle_poller () |
void | flush_remove_later () |
Flush the fdRemoveLater_ and sockRemoveLater_ vector, effectively removing the item for the reactor and poller. | |
long | tickless () |
Calculate min time to wait in poller. | |
Static Private Member Functions | |
static bool | TimerItemCallablePairComp (const TimerItemCallablePair &lhs, const TimerItemCallablePair &rhs) |
Private Attributes | |
std::vector< PollItemCallablePair > | items_ |
std::list< TimerItemCallablePair > | timers_ |
std::vector< const socket_t * > | sockRemoveLater_ |
std::vector< raw_socket_t > | fdRemoveLater_ |
std::vector< timer_id_t > | timerRemoveLater_ |
poller | poller_ |
bool | dispatching_ |
bool | rebuild_poller_ |
Loop object that helps to manage multiple socket by calling a user-defined handler for each socket when a watched event occurs.
Calls assigned user-defined handler for timed events - repeaded and one-shot.
It uses zmq::poller as the underlying polling mechanism.
std::function<bool (void) > zmqpp::loop::Callable |
|
private |
void* zmqpp::loop::timer_id_t |
Type used to identify created timers withing loop.
|
private |
zmqpp::loop::loop | ( | ) |
Construct an empty polling model.
|
virtual |
Cleanup reactor.
Any sockets will need to be closed separately.
|
private |
void zmqpp::loop::add | ( | raw_socket_t const | descriptor, |
Callable | callable, | ||
short const | event = poller::poll_in | poller::poll_error ) |
Add a standard socket to the loop, 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 loop when a registered event occurs on fd. |
event | the event flags to monitor. |
void zmqpp::loop::add | ( | socket_t & | socket, |
Callable | callable, | ||
short const | event = poller::poll_in ) |
Add a socket to the loop, 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 loop when a registered event occurs on socket. |
event | the event flags to monitor on the socket. |
loop::timer_id_t zmqpp::loop::add | ( | std::chrono::milliseconds | delay, |
size_t | times, | ||
Callable | callable ) |
Add a timed event to the loop, providing a handler that will be called when timer fires.
delay | time after which handler will be executed. |
times | how many times should timer be reneved - 0 for infinte ammount. |
callable | the function that will be called by the loop after delay. |
|
private |
Flush the fdRemoveLater_ and sockRemoveLater_ vector, effectively removing the item for the reactor and poller.
void zmqpp::loop::remove | ( | raw_socket_t const | descriptor | ) |
Stop monitoring a standard socket.
descriptor | the standard socket to stop monitoring. |
void zmqpp::loop::remove | ( | socket_t const & | socket | ) |
Stop monitoring a socket.
socket | the socket to stop monitoring. |
void zmqpp::loop::remove | ( | timer_id_t const | timer | ) |
Remove timer event from the loop.
timer | identifier in the loop. |
void zmqpp::loop::reset | ( | timer_id_t const | timer | ) |
Reset timer in the loop, it will start counting delay time again.
Times argument is preserved.
timer | identifier in the loop. |
void zmqpp::loop::start | ( | ) |
Starts loop.
It will block until one of handlers returns false.
|
private |
|
private |
|
private |
Calculate min time to wait in poller.
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |