Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

A bound QUIC endpoint ready to accept connections.

Implementations§

Source§

impl Server

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

The address the endpoint is actually bound to.

Useful when the configured port is 0.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more