cppnet
C++ network utilities for asynchronous servers.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
net::service::async_context Struct Reference

An asynchronous execution context. More...

#include <net/service/async_context.hpp>

Inheritance diagram for net::service::async_context:
net::service::basic_context_thread< Service >

Public Types

enum  signals : std::uint8_t { terminate = 0 , user1 , END }
 An enum of all valid async context signals.
 
enum  context_states : std::uint8_t { PENDING = 0 , STARTED , STOPPED }
 An enum of valid context states.
 
using async_scope = exec::async_scope
 Asynchronous scope type.
 
using multiplexer_type = io::execution::poll_multiplexer
 The io multiplexer type.
 
using triggers = io::execution::basic_triggers< multiplexer_type >
 The io triggers type.
 
using socket_dialog = triggers::socket_dialog
 The socket dialog type.
 
using socket_type = io::socket::native_socket_type
 The socket type.
 
using signal_mask = std::uint64_t
 The signal mask type.
 
using interrupt_source = timers::socketpair_interrupt_source_t
 Interrupt source type.
 
using timers_type = timers::timers< interrupt_source >
 The timers type.
 
using clock = std::chrono::steady_clock
 The clock type.
 
using duration = std::chrono::milliseconds
 The duration type.
 

Public Member Functions

auto signal (int signum) -> void
 Sets the signal mask, then interrupts the service.
 
auto interrupt () const noexcept -> void
 Calls the timers interrupt.
 
template<typename Fn >
requires std::is_invocable_r_v<bool, Fn>
auto isr (const socket_dialog &socket, Fn routine) -> void
 An interrupt service routine for the poller.
 
auto run () -> void
 Runs the event loop.
 

Public Attributes

timers_type timers
 The event loop timers.
 
async_scope scope
 The asynchronous scope.
 
triggers poller
 The poll triggers.
 
std::atomic< signal_masksigmask
 The active signal mask.
 
std::atomic< context_statesstate {PENDING}
 A counter that tracks the context state.
 

Detailed Description

An asynchronous execution context.

Member Function Documentation

◆ isr()

template<typename Fn >
requires std::is_invocable_r_v<bool, Fn>
auto net::service::async_context::isr ( const socket_dialog socket,
Fn  routine 
) -> void

An interrupt service routine for the poller.

When invoked, isr() installs an event handler on socket events received on socket. The routine will be continuously re-installed in a loop until it returns false.

Template Parameters
FnA callable to run upon receiving an interrupt.
Parameters
socketThe listening socket for interrupts. Its lifetime is tied to the lifetime of routine.
routineThe routine to run upon receiving a poll interrupt on socket.
isr(poller.emplace(sockets[0]), [&]() noexcept {
auto sigmask_ = sigmask.exchange(0);
for (int signum = 0; auto mask = (sigmask_ >> signum); ++signum)
{
if (mask & (1 << 0))
service.signal_handler(signum);
}
return !(sigmask_ & (1 << terminate));
});
triggers poller
The poll triggers.
Definition async_context.hpp:66
auto isr(const socket_dialog &socket, Fn routine) -> void
An interrupt service routine for the poller.

◆ signal()

auto net::service::async_context::signal ( int  signum) -> void
inline

Sets the signal mask, then interrupts the service.

Parameters
signumThe signal to send. Must be in range of enum signals.

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