Trait trillium_server_common::ConfigExt
source · pub trait ConfigExt<ServerType, AcceptorType>where
ServerType: Server,{
// Required methods
fn port(&self) -> u16;
fn host(&self) -> String;
fn socket_addrs(&self) -> Vec<SocketAddr>;
fn should_register_signals(&self) -> bool;
fn nodelay(&self) -> bool;
fn stopper(&self) -> Stopper;
fn acceptor(&self) -> &AcceptorType;
fn counter_observer(&self) -> &CloneCounterObserver;
fn graceful_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn handle_stream<'life0, 'async_trait>(
&'life0 self,
stream: ServerType::Transport,
handler: impl 'async_trait + Handler,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn build_listener<Listener>(&self) -> Listener
where Listener: TryFrom<TcpListener>,
<Listener as TryFrom<TcpListener>>::Error: Debug;
fn over_capacity(&self) -> bool;
}
Expand description
§Server-implementer interfaces to Config
These functions are intended for use by authors of trillium servers, and should not be necessary to build an application. Please open an issue if you find yourself using this trait directly in an application.
Required Methods§
sourcefn port(&self) -> u16
fn port(&self) -> u16
resolve a port for this application, either directly
configured, from the environmental variable PORT
, or a default
of 8080
sourcefn host(&self) -> String
fn host(&self) -> String
resolve the host for this application, either directly from
configuration, from the HOST
env var, or "localhost"
sourcefn socket_addrs(&self) -> Vec<SocketAddr>
fn socket_addrs(&self) -> Vec<SocketAddr>
use the ConfigExt::port
and ConfigExt::host
to resolve
a vec of potential socket addrs
sourcefn should_register_signals(&self) -> bool
fn should_register_signals(&self) -> bool
returns whether this server should register itself for
operating system signals. this flag does nothing aside from
communicating to the server implementer that this is
desired. defaults to true on cfg(unix)
systems, and false
elsewhere.
sourcefn nodelay(&self) -> bool
fn nodelay(&self) -> bool
returns whether the server should set TCP_NODELAY on the TcpListener, if that is applicable
sourcefn stopper(&self) -> Stopper
fn stopper(&self) -> Stopper
returns a clone of the Stopper
associated with
this server, to be used in conjunction with signals or other
service interruption methods
sourcefn acceptor(&self) -> &AcceptorType
fn acceptor(&self) -> &AcceptorType
returns the tls acceptor for this server
sourcefn counter_observer(&self) -> &CloneCounterObserver
fn counter_observer(&self) -> &CloneCounterObserver
returns the CloneCounterObserver
for this server
sourcefn graceful_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn graceful_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
waits for the last clone of the CloneCounter
in this
config to drop, indicating that all outstanding requests are
complete
sourcefn handle_stream<'life0, 'async_trait>(
&'life0 self,
stream: ServerType::Transport,
handler: impl 'async_trait + Handler,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle_stream<'life0, 'async_trait>(
&'life0 self,
stream: ServerType::Transport,
handler: impl 'async_trait + Handler,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
apply the provided handler to the transport, using
trillium_http
’s http implementation. this is the default inner
loop for most trillium servers
sourcefn build_listener<Listener>(&self) -> Listener
fn build_listener<Listener>(&self) -> Listener
builds any type that is TryFromstd::net::TcpListener and
configures it for use. most trillium servers should use this if
possible instead of using ConfigExt::port
,
ConfigExt::host
, or ConfigExt::socket_addrs
.
this function also contains logic that sets nonblocking to
true and on unix systems will build a tcp listener from the
LISTEN_FD
env var.
sourcefn over_capacity(&self) -> bool
fn over_capacity(&self) -> bool
determines if the server is currently responding to more than
the maximum number of connections set by
Config::with_max_connections
.