Skip to main content

Module server

Module server 

Source
Expand description

Server accept loop, background tasks, and graceful shutdown.

Contains the runtime infrastructure that sits between the TCP listener and the per-request proxy pipeline. This module is intentionally decoupled from main() so that the server logic remains testable and reusable without pulling in process-level concerns like signal handling or std::process::exit.

Structs§

ServerState
Runtime state shared across the accept loop.

Functions§

serve
Accepts connections on listener, optionally wrapping each in TLS, and dispatches them through the proxy pipeline using the given client and shared state. Generic over the client connector type so that both plain-HTTP and HTTPS upstreams use the same accept loop.
shutdown_signal
Awaits a shutdown signal (SIGINT or SIGTERM on Unix, Ctrl+C on all platforms). Returns once the first signal is received.
spawn_health_checker
Spawns a background task that periodically probes each upstream backend at the configured health check path, updating health state based on HTTP response status.
spawn_rate_limit_cleanup
Spawns a background task that periodically prunes stale entries from the rate limiter, preventing unbounded memory growth.