Skip to main content

udp/hook/
struct.rs

1use crate::*;
2
3/// Default server hook.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct DefaultServerHook;
6
7/// Represents the hooks for managing the server's lifecycle, specifically for waiting and shutting down.
8#[derive(Clone)]
9pub struct ServerControlHook {
10    /// A hook that returns a future, which completes when the server's main task finishes.
11    /// This is typically used to wait for the server to stop accepting connections before
12    /// the application exits.
13    pub(crate) wait_hook: Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync>,
14    /// A hook that, when called, initiates a graceful shutdown of the server.
15    /// This will stop the server from accepting new connections and allow existing ones
16    /// to complete.
17    pub(crate) shutdown_hook: Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync>,
18}
19
20/// Represents the state associated with a single connection handler.
21///
22/// This struct encapsulates the necessary context for processing a connection,
23/// including a reference to the network socket. It is created
24/// for each connection and passed to the relevant handlers.
25#[derive(Clone)]
26pub(crate) struct HandlerState {
27    /// A reference to the underlying network socket for the connection.
28    pub(super) socket: ArcRwLockUdpSocket,
29}