Trait trillium_server_common::ConfigExt [−][src]
pub trait ConfigExt<ServerType: ?Sized, AcceptorType> where
ServerType: Server + ?Sized, {
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(&self) -> &CloneCounterⓘNotable traits for CloneCounterimpl Future for CloneCounter type Output = ();
;
fn graceful_shutdown<'async_trait>(
self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where
Self: 'async_trait;
fn handle_stream<'async_trait>(
self,
stream: ServerType::Transport,
handler: impl Handler
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where
Self: '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
resolve a port for this application, either directly
configured, from the environmental variable PORT
, or a default
of 8080
resolve the host for this application, either directly from
configuration, from the HOST
env var, or "localhost"
fn 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
fn 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.
returns whether the server should set TCP_NODELAY on the TcpListener, if that is applicable
returns a clone of the Stopper
associated with
this server, to be used in conjunction with signals or other
service interruption methods
fn counter(&self) -> &CloneCounterⓘNotable traits for CloneCounterimpl Future for CloneCounter type Output = ();
fn counter(&self) -> &CloneCounterⓘNotable traits for CloneCounterimpl Future for CloneCounter type Output = ();
impl Future for CloneCounter type Output = ();
returns the CloneCounter
for this server. please note that
cloning this type has implications for graceful shutdown and
needs to be done with care.
waits for the last clone of the CloneCounter
in this
config to drop, indicating that all outstanding requests are
complete
apply the provided handler to the transport, using
trillium_http
’s http implementation. this is the default inner
loop for most trillium servers
fn build_listener<Listener>(&self) -> Listener where
Listener: TryFrom<TcpListener>,
<Listener as TryFrom<TcpListener>>::Error: Debug,
fn build_listener<Listener>(&self) -> Listener where
Listener: TryFrom<TcpListener>,
<Listener as TryFrom<TcpListener>>::Error: Debug,
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.
fn 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
.