![]() |
libfilezilla
|
Simple handler for asynchronous event processing. More...
#include <event_handler.hpp>
Public Member Functions | |
event_handler (event_loop &loop) | |
event_handler (event_handler const &)=delete | |
event_handler & | operator= (event_handler const &)=delete |
void | remove_handler () |
Deactivates handler, removes all pending events and stops all timers for this handler. More... | |
virtual void | operator() (event_base const &)=0 |
Called by the event loop in the worker thread with the event to process. More... | |
template<typename T , typename... Args> | |
void | send_event (Args &&... args) |
template<typename T > | |
void | send_event (T *evt) |
timer_id | add_timer (duration const &interval, bool one_shot) |
Adds a timer, returns the timer id. More... | |
void | stop_timer (timer_id id) |
Public Attributes | |
event_loop & | event_loop_ |
Friends | |
class | event_loop |
Simple handler for asynchronous event processing.
Usage example:
timer_id add_timer | ( | duration const & | interval, |
bool | one_shot | ||
) |
Adds a timer, returns the timer id.
Once the interval expires, you get a timer event from the event loop.
One-shot timers are deleted automatically
For periodic timers, the next event is scheduled right before the callback is called. If multiple intervals expire before the timer fires, e.g. under heavy load, only one event is sent.
If multiple different timers have expired, the order in which the callbacks are executed is unspecified, there is no fairness guarantee.
Timers take precedence over other queued events.
|
pure virtual |
Called by the event loop in the worker thread with the event to process.
Override in your derived class.
Consider using dispatch inside your function.
void remove_handler | ( | ) |
Deactivates handler, removes all pending events and stops all timers for this handler.
When function returns, handler is not in its callback anymore.
This may deadlock if a handler removes itself inside its own callback.
void stop_timer | ( | timer_id | id | ) |
Stops the given timer.
One-shot timers that have fired stop automatically and do not need to be stopped.