qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
Asynchronous System

Core mechanisms for event-driven asynchronous programming. More...

Collaboration diagram for Asynchronous System:

Topics

 Asynchronous I/O Events
 Specific event types for asynchronous I/O operations.

Files

file  io_handler.h
 Session management for the asynchronous IO framework.
file  listener.h
 Core event loop manager for the asynchronous IO framework.

Classes

struct  qb::io::use< _Derived >
 Helper template providing type aliases for integrating qb-io asynchronous components. More...
interface  qb::io::async::IRegisteredKernelEvent
 Interface for kernel event registration and invocation. More...
class  qb::io::async::base< _Derived, _EV_EVENT >
 Base class for all qb-io asynchronous components that interact with the event listener. More...
class  qb::io::async::with_timeout< _Derived >
 CRTP base class that adds timeout functionality to derived asynchronous components. More...
class  qb::io::async::Timeout< _Func >
 Utility class to execute a function after a specified timeout using the event loop. More...
class  qb::io::async::input< _Derived >
 CRTP base class for managing asynchronous input operations with protocol processing. More...
class  qb::io::async::output< _Derived >
 CRTP base class for managing asynchronous output operations. More...
class  qb::io::async::io< _Derived >
 CRTP base class for managing bidirectional asynchronous I/O operations with protocol processing. More...
class  qb::io::async::io_handler< _Derived, _Session >
 Session manager for asynchronous IO. More...
class  qb::io::async::listener
 Central event loop manager for asynchronous IO operations. More...

Functions

template<typename _Func>
void qb::io::async::callback (_Func &&func, double timeout=0.)
 Utility function to schedule a callable for execution after a timeout.
void qb::io::async::init ()
 Initialize the asynchronous event system for the current thread.
std::size_t qb::io::async::run (int flag=0)
 Run the event loop for the current thread.
std::size_t qb::io::async::run_once ()
 Run the event loop once for the current thread, waiting for at least one event.
std::size_t qb::io::async::run_until (bool const &status)
 Run the event loop for the current thread until a condition is met.
void qb::io::async::break_parent ()
 Request the parent (current thread's) event loop to break.

Detailed Description

Core mechanisms for event-driven asynchronous programming.

Includes the event listener (`qb::io::async::listener`), base async I/O classes (`qb::io::async::io`), and timed callbacks (`qb::io::async::callback`).

Function Documentation

◆ callback()

template<typename _Func>
void qb::io::async::callback ( _Func && func,
double timeout = 0. )

Utility function to schedule a callable for execution after a timeout.

Template Parameters
_FuncThe type of the callable (function, lambda, functor).
Parameters
funcThe callable to execute. It is moved into the internal Timeout object.
timeoutTimeout duration in seconds before execution. A timeout of 0.0 (or less) typically means the callback will be scheduled for the next iteration of the event loop, or executed immediately if the Timeout class logic handles it that way.

This function creates a Timeout<_Func> object on the heap (new Timeout), which then manages its own lifetime, deleting itself after func is called. It provides a convenient way to achieve delayed execution without manual timer management.

◆ init()

void qb::io::async::init ( )
inline

Initialize the asynchronous event system for the current thread.

Ensures that listener::current is available and ready for use. Typically called once per thread that will use qb-io asynchronous features standalone. Not usually needed when using qb-core as qb::Main handles this for its VirtualCore threads.

◆ run()

std::size_t qb::io::async::run ( int flag = 0)
inline

Run the event loop for the current thread.

Executes the current thread's listener::current.run(flag). This is the primary way to process asynchronous events in a standalone qb-io application.

Parameters
flagThe libev run flag (e.g., EVRUN_NOWAIT, EVRUN_ONCE). See listener::run().
Returns
The number of events that were invoked during this run.

◆ run_once()

std::size_t qb::io::async::run_once ( )
inline

Run the event loop once for the current thread, waiting for at least one event.

Equivalent to listener::current.run(EVRUN_ONCE).

Returns
The number of events invoked.

◆ run_until()

std::size_t qb::io::async::run_until ( bool const & status)
inline

Run the event loop for the current thread until a condition is met.

Repeatedly calls listener::current.run(EVRUN_NOWAIT) as long as the status is true.

Parameters
statusReference to a boolean condition. The loop continues as long as status is true.
Returns
The total number of events invoked across all run(EVRUN_NOWAIT) calls.

◆ break_parent()

void qb::io::async::break_parent ( )
inline

Request the parent (current thread's) event loop to break.

Calls listener::current.break_one().