|
cppnet
C++ network utilities for asynchronous servers.
|
An asynchronous execution context. More...
#include <net/service/async_context.hpp>
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_mask > | sigmask |
| The active signal mask. | |
| std::atomic< context_states > | state {PENDING} |
| A counter that tracks the context state. | |
An asynchronous execution context.
| 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.
| Fn | A callable to run upon receiving an interrupt. |
| socket | The listening socket for interrupts. Its lifetime is tied to the lifetime of routine. |
| routine | The routine to run upon receiving a poll interrupt on socket. 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));
});
auto isr(const socket_dialog &socket, Fn routine) -> void An interrupt service routine for the poller. |
|
inline |
Sets the signal mask, then interrupts the service.
| signum | The signal to send. Must be in range of enum signals. |