MySQL 9.1.0
Source Code Documentation
net::io_context Class Reference

#include <io_context.h>

Inheritance diagram for net::io_context:
[legend]

Classes

class  async_op
 base class of async operation. More...
 
class  async_op_impl
 async operation with callback. More...
 
class  AsyncOps
 
class  DeferredWork
 queued work from io_context::executor_type::dispatch()/post()/defer(). More...
 
class  executor_type
 
class  monitor
 
class  timer_queue
 
class  timer_queue_base
 

Public Types

using count_type = size_t
 
using native_handle_type = impl::socket::native_handle_type
 

Public Member Functions

 io_context ()
 
 io_context (std::unique_ptr< net::impl::socket::SocketServiceBase > &&socket_service, std::unique_ptr< IoServiceBase > &&io_service)
 
 io_context (int)
 
 ~io_context ()
 
 io_context (const io_context &)=delete
 
io_contextoperator= (const io_context &)=delete
 
executor_type get_executor () noexcept
 
count_type run ()
 
template<class Rep , class Period >
count_type run_for (const std::chrono::duration< Rep, Period > &rel_time)
 
template<class Clock , class Duration >
count_type run_until (const std::chrono::time_point< Clock, Duration > &abs_time)
 
count_type run_one ()
 
template<class Rep , class Period >
count_type run_one_for (const std::chrono::duration< Rep, Period > &rel_time)
 
template<class Clock , class Duration >
count_type run_one_until (const std::chrono::time_point< Clock, Duration > &abs_time)
 
count_type poll ()
 
count_type poll_one ()
 
void stop ()
 
bool stopped () const noexcept
 
void restart ()
 
impl::socket::SocketServiceBasesocket_service () const
 
IoServiceBaseio_service () const
 
stdx::expected< void, std::error_code > open_res () const noexcept
 get the status of the implicit open() call of the io-service. More...
 
- Public Member Functions inherited from net::execution_context
 execution_context ()=default
 
 execution_context (const execution_context &)=delete
 
execution_contextoperator= (const execution_context &)=delete
 
virtual ~execution_context ()
 
void notify_fork (fork_event e)
 

Private Member Functions

template<class Func , class ProtoAllocator >
void defer_work (Func &&f, const ProtoAllocator &a)
 defer work for later execution. More...
 
template<class Clock , class Duration >
count_type do_one_until (std::unique_lock< std::mutex > &lk, const std::chrono::time_point< Clock, Duration > &abs_time)
 
count_type do_one (std::unique_lock< std::mutex > &lk, std::chrono::milliseconds timeout)
 
bool has_outstanding_work () const
 
stdx::expected< void, std::error_code > cancel (native_handle_type fd)
 cancel all async-ops of a file-descriptor. More...
 
template<class Op >
void async_wait (native_handle_type fd, impl::socket::wait_type wt, Op &&op)
 
template<class Timer , class Op >
void async_wait (const Timer &timer, Op &&op)
 async wait for a timer expire. More...
 
template<class Timer >
size_t cancel (const Timer &timer)
 cancel all async-ops of a timer. More...
 
template<class Timer >
size_t cancel_one (const Timer &)
 
void wait_no_runner_ (std::unique_lock< std::mutex > &lk)
 
void wait_no_runner_unlocked_ (std::unique_lock< std::mutex > &lk)
 
void wake_one_runner_ (std::unique_lock< std::mutex > &lk)
 
void is_running (bool v)
 
bool is_running () const
 
void notify_io_service_if_not_running_in_this_thread ()
 

Private Attributes

DeferredWork deferred_work_
 
bool stopped_ {false}
 
std::atomic< count_typework_count_ {}
 
std::unique_ptr< impl::socket::SocketServiceBasesocket_service_
 
std::unique_ptr< IoServiceBaseio_service_
 
stdx::expected< void, std::error_code > io_service_open_res_
 
AsyncOps active_ops_
 
std::list< std::unique_ptr< async_op > > cancelled_ops_
 
std::vector< timer_queue_base * > timer_queues_
 pointers to the timer-queues of this io-contexts. More...
 
std::mutex mtx_ {}
 mutex that protects the core parts of the io-context. More...
 
std::mutex do_one_mtx_ {}
 
std::condition_variable do_one_cond_ {}
 
bool is_running_ {false}
 

Friends

template<typename _Clock , typename _WaitTraits >
class basic_waitable_timer
 
class basic_socket_impl_base
 
template<class Protocol >
class basic_socket_impl
 
template<class Protocol >
class basic_socket
 
template<class Protocol >
class basic_stream_socket
 
template<class Protocol >
class basic_socket_acceptor
 

Additional Inherited Members

- Protected Types inherited from net::execution_context
using service_key_type = std::type_index
 
- Protected Member Functions inherited from net::execution_context
void shutdown () noexcept
 
void destroy () noexcept
 
template<typename Service , class... Args>
serviceadd_service (Args &&...args)
 
- Static Protected Member Functions inherited from net::execution_context
template<class Service >
static void service_deleter (service *svc)
 
template<class Key >
static service_key_type service_key ()
 maps selected type to unique identifier. More...
 
- Protected Attributes inherited from net::execution_context
std::mutex services_mtx_
 
std::list< ServicePtrservices_
 
std::unordered_map< service_key_type, service * > keys_
 

Member Typedef Documentation

◆ count_type

◆ native_handle_type

Constructor & Destructor Documentation

◆ io_context() [1/4]

net::io_context::io_context ( )
inline

◆ io_context() [2/4]

net::io_context::io_context ( std::unique_ptr< net::impl::socket::SocketServiceBase > &&  socket_service,
std::unique_ptr< IoServiceBase > &&  io_service 
)
inline

◆ io_context() [3/4]

net::io_context::io_context ( int  )
inlineexplicit

◆ ~io_context()

net::io_context::~io_context ( )
inline

◆ io_context() [4/4]

net::io_context::io_context ( const io_context )
delete

Member Function Documentation

◆ async_wait() [1/2]

template<class Timer , class Op >
void net::io_context::async_wait ( const Timer &  timer,
Op &&  op 
)
inlineprivate

async wait for a timer expire.

adds the op and timer to the timer_queue

Parameters
timertimer
opcompletion handler to call when timer is triggered

◆ async_wait() [2/2]

template<class Op >
void net::io_context::async_wait ( native_handle_type  fd,
impl::socket::wait_type  wt,
Op &&  op 
)
inlineprivate

◆ cancel() [1/2]

template<class Timer >
size_t net::io_context::cancel ( const Timer &  timer)
inlineprivate

cancel all async-ops of a timer.

◆ cancel() [2/2]

stdx::expected< void, std::error_code > net::io_context::cancel ( native_handle_type  fd)
inlineprivate

cancel all async-ops of a file-descriptor.

◆ cancel_one()

template<class Timer >
size_t net::io_context::cancel_one ( const Timer &  )
inlineprivate

◆ defer_work()

template<class Func , class ProtoAllocator >
void net::io_context::defer_work ( Func &&  f,
const ProtoAllocator &  a 
)
inlineprivate

defer work for later execution.

◆ do_one()

io_context::count_type net::io_context::do_one ( std::unique_lock< std::mutex > &  lk,
std::chrono::milliseconds  timeout 
)
inlineprivate

◆ do_one_until()

template<class Clock , class Duration >
io_context::count_type net::io_context::do_one_until ( std::unique_lock< std::mutex > &  lk,
const std::chrono::time_point< Clock, Duration > &  abs_time 
)
inlineprivate

◆ get_executor()

io_context::executor_type net::io_context::get_executor ( )
inlinenoexcept

◆ has_outstanding_work()

bool net::io_context::has_outstanding_work ( ) const
inlineprivate

◆ io_service()

IoServiceBase * net::io_context::io_service ( ) const
inline

◆ is_running() [1/2]

bool net::io_context::is_running ( ) const
inlineprivate

◆ is_running() [2/2]

void net::io_context::is_running ( bool  v)
inlineprivate

◆ notify_io_service_if_not_running_in_this_thread()

void net::io_context::notify_io_service_if_not_running_in_this_thread ( )
inlineprivate

◆ open_res()

stdx::expected< void, std::error_code > net::io_context::open_res ( ) const
inlinenoexcept

get the status of the implicit open() call of the io-service.

the io_service_.open() may fail due to out-of-file-descriptors.

run() will fail silently if the io-service failed to open.

Returns
std::error_code on error

◆ operator=()

io_context & net::io_context::operator= ( const io_context )
delete

◆ poll()

io_context::count_type net::io_context::poll ( )
inline

◆ poll_one()

io_context::count_type net::io_context::poll_one ( )
inline

◆ restart()

void net::io_context::restart ( )
inline

◆ run()

io_context::count_type net::io_context::run ( )
inline

◆ run_for()

template<class Rep , class Period >
io_context::count_type net::io_context::run_for ( const std::chrono::duration< Rep, Period > &  rel_time)

◆ run_one()

io_context::count_type net::io_context::run_one ( )
inline

◆ run_one_for()

template<class Rep , class Period >
io_context::count_type net::io_context::run_one_for ( const std::chrono::duration< Rep, Period > &  rel_time)
inline

◆ run_one_until()

template<class Clock , class Duration >
io_context::count_type net::io_context::run_one_until ( const std::chrono::time_point< Clock, Duration > &  abs_time)
inline

◆ run_until()

template<class Clock , class Duration >
io_context::count_type net::io_context::run_until ( const std::chrono::time_point< Clock, Duration > &  abs_time)

◆ socket_service()

impl::socket::SocketServiceBase * net::io_context::socket_service ( ) const
inline

◆ stop()

void net::io_context::stop ( )
inline

◆ stopped()

bool net::io_context::stopped ( ) const
inlinenoexcept

◆ wait_no_runner_()

void net::io_context::wait_no_runner_ ( std::unique_lock< std::mutex > &  lk)
inlineprivate

◆ wait_no_runner_unlocked_()

void net::io_context::wait_no_runner_unlocked_ ( std::unique_lock< std::mutex > &  lk)
inlineprivate

◆ wake_one_runner_()

void net::io_context::wake_one_runner_ ( std::unique_lock< std::mutex > &  lk)
inlineprivate

Friends And Related Function Documentation

◆ basic_socket

template<class Protocol >
friend class basic_socket
friend

◆ basic_socket_acceptor

template<class Protocol >
friend class basic_socket_acceptor
friend

◆ basic_socket_impl

template<class Protocol >
friend class basic_socket_impl
friend

◆ basic_socket_impl_base

friend class basic_socket_impl_base
friend

◆ basic_stream_socket

template<class Protocol >
friend class basic_stream_socket
friend

◆ basic_waitable_timer

template<typename _Clock , typename _WaitTraits >
friend class basic_waitable_timer
friend

Member Data Documentation

◆ active_ops_

AsyncOps net::io_context::active_ops_
private

◆ cancelled_ops_

std::list<std::unique_ptr<async_op> > net::io_context::cancelled_ops_
private

◆ deferred_work_

DeferredWork net::io_context::deferred_work_
private

◆ do_one_cond_

std::condition_variable net::io_context::do_one_cond_ {}
mutableprivate

◆ do_one_mtx_

std::mutex net::io_context::do_one_mtx_ {}
mutableprivate

◆ io_service_

std::unique_ptr<IoServiceBase> net::io_context::io_service_
private

◆ io_service_open_res_

stdx::expected<void, std::error_code> net::io_context::io_service_open_res_
private

◆ is_running_

bool net::io_context::is_running_ {false}
private

◆ mtx_

std::mutex net::io_context::mtx_ {}
mutableprivate

mutex that protects the core parts of the io-context.

  • timer_queues_

◆ socket_service_

std::unique_ptr<impl::socket::SocketServiceBase> net::io_context::socket_service_
private

◆ stopped_

bool net::io_context::stopped_ {false}
private

◆ timer_queues_

std::vector<timer_queue_base *> net::io_context::timer_queues_
private

pointers to the timer-queues of this io-contexts.

timer-queues are one per timer-type (std::chrono::steady_clock, std::chrono::system_clock, ...)

timer_queue_base is the base class of the timer-queues

the timer-queue's themselves are ownered by the io_context's executor via execution_context::add_service()

protected via 'mtx_'

◆ work_count_

std::atomic<count_type> net::io_context::work_count_ {}
private

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