libfilezilla
|
A threaded event loop that supports sending events and timers. More...
#include <event_loop.hpp>
Public Types | |
enum | loop_option { threadless } |
typedef std::deque< std::pair< event_handler *, event_base * > > | Events |
Public Member Functions | |
event_loop () | |
Spawns a thread and starts the loop. | |
event_loop (thread_pool &pool) | |
Takes a thread from the pool and starts the loop. | |
event_loop (loop_option) | |
~event_loop () | |
Stops the thread. | |
event_loop (event_loop const &)=delete | |
event_loop & | operator= (event_loop const &)=delete |
void | filter_events (std::function< bool(Events::value_type &)> const &filter) |
Allows filtering of queued events. More... | |
void | stop (bool join=false) |
Stops the loop. More... | |
void | run () |
Starts the loop in the caller's thread. | |
bool | running () const |
Friends | |
class | event_handler |
A threaded event loop that supports sending events and timers.
Timers have precedence over queued events. Too many or too frequent timers can starve processing queued events.
If the deadlines of multiple timers have expired, they get processed in an unspecified order.
void filter_events | ( | std::function< bool(Events::value_type &)> const & | filter | ) |
Allows filtering of queued events.
Puts all queued events through the filter function. The filter function can freely change the passed events. If the filter function returns true, the corresponding event gets removed.
The filter function must not call any function of event_loop.
Filtering events is a blocking operation and temporarily pauses the loop.
void stop | ( | bool | join = false | ) |
Stops the loop.
Stops the event loop. It is automatically called by the destructor.
Does not wait for the loop if the join argument isn't set.