Kea 3.1.3
isc::asiolink::IOService Class Reference

The IOService class is a wrapper for the ASIO io_context class. More...

#include <io_service.h>

Public Member Functions

 IOService ()
 The constructor.
 
 ~IOService ()
 The destructor.
 
boost::asio::io_context & getInternalIOService ()
 Return the native io_context object used in this wrapper.
 
size_t poll ()
 Run the underlying event loop for a ready events.
 
size_t pollOne ()
 Run the underlying event loop for a ready events.
 
void post (const std::function< void()> &callback)
 Post a callback to the end of the queue.
 
void restart ()
 Restarts the IOService in preparation for a subsequent run() invocation.
 
void run ()
 Start the underlying event loop.
 
size_t runOne ()
 Run the underlying event loop for a single event.
 
size_t runOneFor (size_t wait_time_usecs, bool &timed_out)
 Run the underlying event loop for a single event or until a wait time expires.
 
void stop ()
 Stop the underlying event loop.
 
void stopAndPoll (bool ignore_errors=true)
 Stop and poll to handle all registered events.
 
bool stopped () const
 Indicates if the IOService has been stopped.
 
void stopWork ()
 Removes IO service work object to let it finish running when all handlers have been invoked.
 

Detailed Description

The IOService class is a wrapper for the ASIO io_context class.

Definition at line 32 of file io_service.h.

Constructor & Destructor Documentation

◆ IOService()

isc::asiolink::IOService::IOService ( )

The constructor.

Definition at line 150 of file io_service.cc.

◆ ~IOService()

isc::asiolink::IOService::~IOService ( )

The destructor.

Definition at line 153 of file io_service.cc.

Member Function Documentation

◆ getInternalIOService()

boost::asio::io_context & isc::asiolink::IOService::getInternalIOService ( )

Return the native io_context object used in this wrapper.

This is a short term work around to support other Kea modules that share the same io_context with the authoritative server. It will eventually be removed once the wrapper interface is generalized.

Returns
The internal io_context object.

Definition at line 202 of file io_service.cc.

◆ poll()

size_t isc::asiolink::IOService::poll ( )

Run the underlying event loop for a ready events.

This method executes handlers for all ready events and returns. It will return immediately if there are no ready events.

Returns
The number of handlers that were executed.

Definition at line 172 of file io_service.cc.

Referenced by stopAndPoll().

◆ pollOne()

size_t isc::asiolink::IOService::pollOne ( )

Run the underlying event loop for a ready events.

This method executes handlers for all ready events and returns. It will return immediately if there are no ready events.

Returns
The number of handlers that were executed.

Definition at line 177 of file io_service.cc.

◆ post()

void isc::asiolink::IOService::post ( const std::function< void()> & callback)

Post a callback to the end of the queue.

Requests the callback be called sometime later. It is not guaranteed by the underlying asio, but it can reasonably be expected the callback is put to the end of the callback queue. It is not called from within this function.

It may be used to implement "background" work, for example (doing stuff by small bits that are called from time to time).

Definition at line 207 of file io_service.cc.

◆ restart()

void isc::asiolink::IOService::restart ( )

Restarts the IOService in preparation for a subsequent run() invocation.

Definition at line 192 of file io_service.cc.

Referenced by stopAndPoll().

◆ run()

void isc::asiolink::IOService::run ( )

Start the underlying event loop.

This method does not return control to the caller until the stop() or stopWork() method is called via some handler.

Definition at line 157 of file io_service.cc.

◆ runOne()

size_t isc::asiolink::IOService::runOne ( )

Run the underlying event loop for a single event.

This method return control to the caller as soon as the first handler has completed. (If no handlers are ready when it is run, it will block until one is.)

Returns
The number of handlers that were executed.

Definition at line 162 of file io_service.cc.

◆ runOneFor()

size_t isc::asiolink::IOService::runOneFor ( size_t wait_time_usecs,
bool & timed_out )

Run the underlying event loop for a single event or until a wait time expires.

This method returns control to the caller as soon as the first handler has completed or the wait time elapses. If the number of handlers executed is zero and timed_out is set to false this indicates that the IOService was stopped.

Parameters
wait_time_usecswait time in microseconds.
[out]timed_outset to true if the wait time expired without any handlers executing. timed_out parameter will be set true if the wait time elapsed.
Returns
The number of handlers that were executed.

Definition at line 167 of file io_service.cc.

◆ stop()

void isc::asiolink::IOService::stop ( )

Stop the underlying event loop.

This will return the control to the caller of the run() method.

Definition at line 182 of file io_service.cc.

Referenced by stopAndPoll().

◆ stopAndPoll()

void isc::asiolink::IOService::stopAndPoll ( bool ignore_errors = true)

Stop and poll to handle all registered events.

Parameters
ignore_errorsFlag which indicates if errors should be ignored.

Definition at line 212 of file io_service.cc.

References poll(), restart(), and stop().

+ Here is the call graph for this function:

◆ stopped()

bool isc::asiolink::IOService::stopped ( ) const

Indicates if the IOService has been stopped.

Returns
true if the IOService has been stopped, false otherwise.

Definition at line 187 of file io_service.cc.

◆ stopWork()

void isc::asiolink::IOService::stopWork ( )

Removes IO service work object to let it finish running when all handlers have been invoked.

Definition at line 197 of file io_service.cc.


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