pub struct Server { /* private fields */ }Expand description
A bound QUIC endpoint ready to accept connections.
Implementations§
Source§impl Server
impl Server
Sourcepub fn bind(config: Arc<Config>) -> Result<Self>
pub fn bind(config: Arc<Config>) -> Result<Self>
Binds the UDP socket and prepares the QUIC server configuration.
quinn::Endpoint::server is expanded by hand here, because the socket has
to be reachable between the bind and the endpoint: quinn’s own helper is a
bare std::net::UdpSocket::bind and never touches SO_RCVBUF/SO_SNDBUF,
so a server that does not ask keeps net.core.rmem_default — around
208 KiB — however high net.core.rmem_max is set, that sysctl being a
ceiling on requests rather than an allocation (D56). Everything passed to
[quinn::Endpoint::new_with_abstract_socket] below is what the helper
passes internally; none of it may be dropped in the name of tidiness.
The second reason for expanding it is Gate, which wraps the socket
the runtime hands back so that a datagram quinn would answer can be
refused before quinn sees it (D106). The wrapper is installed whether or
not [security] expected_sni is set, because the list is reloadable and
the socket is not: with an empty list every datagram passes through
untouched, and a SIGHUP can then turn the gate on without a restart.
Sourcepub fn shutdown_trigger(&self) -> Trigger
pub fn shutdown_trigger(&self) -> Trigger
A handle that starts the graceful shutdown.
The binary hands this to its signal handler; tests fire it directly.
Sourcepub fn shutdown_grace(&self) -> Duration
pub fn shutdown_grace(&self) -> Duration
The server.shutdown_grace in force now, which a reload may have moved.
Read from the live configuration rather than from a copy taken at bind,
because server.shutdown_grace is a reloadable key and both readers have
to see the same value: Server::drain bounds the drain with it, and
main bounds the blocking pool with it after the runtime has stopped.
crate::shutdown::blocking_grace states that as an invariant.
Sourcepub fn reload_handle(&self) -> ReloadHandle
pub fn reload_handle(&self) -> ReloadHandle
A handle that replaces the running configuration.
The binary hands this to its SIGHUP handler; tests call it directly.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
The address the endpoint is actually bound to.
Useful when the configured port is 0.
Sourcepub async fn run(&self)
pub async fn run(&self)
Accepts connections until the endpoint closes or shutdown is triggered.
Each connection is handled in its own task, so a failure only ever affects
that connection. The tasks are tracked in a JoinSet rather than detached,
because the shutdown path needs to know when they are finished — and
because dropping the set is what finally cuts off anything still running
once the grace period is over.