libfilezilla
Loading...
Searching...
No Matches
event_loop Class Referencefinal

A threaded event loop that supports sending events and timers. More...

#include <event_loop.hpp>

Public Types

enum  loop_option { threadless }

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_loopoperator= (event_loop const &)=delete
void filter_events (std::function< bool(event_handler *&, event_base &)> const &filter)
 Allows filtering of queued events.
void stop (bool join=false)
 Stops the loop.
void run ()
 Starts the loop in the caller's thread.
bool running () const
void resend_current_event ()

Friends

class event_handler

Detailed Description

A threaded event loop that supports sending events and timers.

Timers abd queued events are treated fairly, neither can starve the other by being too frequent.

If the deadlines of multiple timers have expired, they get processed in an unspecified order.

See also
event_handler for a complete usage example.
Examples
aio.cpp, events.cpp, https.cpp, nonblocking_process.cpp, raw_https.cpp, and timer_fizzbuzz.cpp.

Member Function Documentation

◆ filter_events()

void filter_events ( std::function< bool(event_handler *&, event_base &)> 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.

◆ stop()

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.

Examples
aio.cpp.

The documentation for this class was generated from the following file: