bitfold_host/
event_types.rs

1//! Event and action types for the runtime layer.
2//!
3//! This module defines the core types used for communication between
4//! the connection layer and the user:
5//! - `Action`: Instructions from connections to the runtime (send bytes or emit events)
6//! - `SocketEvent`: Events emitted to the user (packets, connections, disconnections)
7
8use std::net::SocketAddr;
9
10use bitfold_protocol::packet::Packet;
11
12/// Actions that connections can request from the runtime.
13/// Used by the Connection trait to return instructions to the connection manager.
14#[derive(Debug)]
15pub enum Action<E> {
16    /// Send the given bytes to the connection's remote address
17    Send(Vec<u8>),
18    /// Emit an event to the user
19    Emit(E),
20}
21
22/// Events that can occur and are pushed through the event_receiver.
23/// These are user-facing events emitted by the socket/connection manager.
24#[derive(Debug, PartialEq)]
25pub enum SocketEvent {
26    /// A packet was received from a client.
27    Packet(Packet),
28    /// A new connection has been established.
29    Connect(SocketAddr),
30    /// The client has been idling longer than the idle_connection_timeout.
31    Timeout(SocketAddr),
32    /// The established connection to a client has timed out.
33    Disconnect(SocketAddr),
34}