uvcc
libuv C++ bindings
uv::loop Class Reference

The I/O event loop class. More...

#include "loop.hpp"

Public Types

using uv_t = ::uv_loop_t
 
using on_destroy_t = std::function< void(void *_data) >
 The function type of the callback called when the loop instance is about to be destroyed.
 
using on_exit_t = std::function< void(loop _loop) >
 The function type of the callback called after the loop exit.
 
template<typename... _Args_>
using on_walk_t = std::function< void(handle _handle, _Args_ &&... _args) >
 The function type of the callback called by the walk() function. More...
 

Public Member Functions

 loop ()
 Create a new event loop.
 
 loop (const loop &_that)
 
loopoperator= (const loop &_that)
 
 loop (loop &&_that) noexcept
 
loopoperator= (loop &&_that) noexcept
 
void swap (loop &_that) noexcept
 
long nrefs () const noexcept
 The current number of existing references to the same loop as this variable refers to.
 
int uv_status () const noexcept
 The status value returned by the last executed libuv API function.
 
on_destroy_ton_destroy () const noexcept
 
on_exit_ton_exit () const noexcept
 
void *const & data () const noexcept
 
void *& data () noexcept
 
template<typename... _Args_>
int configure (::uv_loop_option _opt, _Args_ &&... _args)
 Set additional loop options. More...
 
int run (::uv_run_mode _mode)
 Go into a loop and process events and their callbacks with the current thread. More...
 
void stop ()
 Stop the event loop. More...
 
int is_alive () const noexcept
 Returns non-zero if there are active handles or request in the loop.
 
int backend_fd () const noexcept
 
int backend_timeout () const noexcept
 Get the poll timeout. The return value is in milliseconds, or -1 for no timeout.
 
uint64_t now () const noexcept
 
void update_time () noexcept
 
template<class _Func_ , typename... _Args_, typename = std::enable_if_t< std::is_convertible< _Func_, on_walk_t< _Args_&&... > >::value >>
void walk (_Func_ &&_walk_cb, _Args_ &&... _args)
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
 operator bool () const noexcept
 Equivalent to (uv_status() >= 0).
 

Static Public Member Functions

static loopDefault () noexcept
 Returns the initialized loop that can be used as a global default loop throughout the program. More...
 

Detailed Description

The I/O event loop class.

All event loops (including the default one) are the instances of this class.

See also
libuv API documentation: uv_loop_t.

Definition at line 33 of file loop.hpp.

Member Typedef Documentation

◆ on_walk_t

template<typename... _Args_>
using uv::loop::on_walk_t = std::function< void(handle _handle, _Args_&&... _args) >

The function type of the callback called by the walk() function.

See also
libuv API documentation: uv_walk_cb, uv_walk().

Definition at line 53 of file loop.hpp.

Member Function Documentation

◆ Default()

static loop& uv::loop::Default ( )
inlinestaticnoexcept

Returns the initialized loop that can be used as a global default loop throughout the program.

Definition at line 220 of file loop.hpp.

◆ data()

void* const& uv::loop::data ( ) const
inlinenoexcept

The pointer to the user-defined arbitrary data.

See also
libuv API documentation: uv_loop_t.data.

Definition at line 238 of file loop.hpp.

◆ configure()

template<typename... _Args_>
int uv::loop::configure ( ::uv_loop_option  _opt,
_Args_ &&...  _args 
)
inline

Set additional loop options.

See also
libuv API documentation: uv_loop_configure().

Definition at line 244 of file loop.hpp.

◆ run()

int uv::loop::run ( ::uv_run_mode  _mode)
inline

Go into a loop and process events and their callbacks with the current thread.

The function acts and returns depending on circumstances which processing is defined by the _mode argument.

See also
libuv API documentation: uv_run(), uv_run_mode.
Note
If you start a loop with this function within a callback executed by another loop the first one will be "blocked" until the second started loop ends and the function returns.

Definition at line 255 of file loop.hpp.

◆ stop()

void uv::loop::stop ( )
inline

Stop the event loop.

See also
libuv API documentation: uv_stop().

Definition at line 272 of file loop.hpp.

◆ backend_fd()

int uv::loop::backend_fd ( ) const
inlinenoexcept

Get backend file descriptor.

See also
libuv API documentation: uv_backend_fd().

Definition at line 279 of file loop.hpp.

◆ now()

uint64_t uv::loop::now ( ) const
inlinenoexcept

Return the current timestamp in milliseconds.

See also
libuv API documentation: uv_now().

Definition at line 284 of file loop.hpp.

◆ update_time()

void uv::loop::update_time ( )
inlinenoexcept

Update the event loop’s concept of “now”.

See also
libuv API documentation: uv_update_time().

Definition at line 288 of file loop.hpp.

◆ walk()

template<class _Func_ , typename... _Args_, typename = std::enable_if_t< std::is_convertible< _Func_, on_walk_t< _Args_&&... > >::value >>
void uv::loop::walk ( _Func_ &&  _walk_cb,
_Args_ &&...  _args 
)
inline

Walk the list of active handles referenced by the loop: for each handle _walk_cb will be executed with the given _args.

Note
All arguments are copied (or moved) to the callback function object. For passing arguments by reference when some callback parameters are used as output ones, wrap corresponding arguments with std::ref() or pass them through raw pointer parameters.

Definition at line 298 of file loop.hpp.


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