Struct trillium_server_common::Config [−][src]
pub struct Config<ServerType: ?Sized, AcceptorType> { /* fields omitted */ }
Expand description
Primary entrypoint for configuring and running a trillium server
The associated methods on this struct are intended to be chained.
Example
trillium_smol::config() // or trillium_async_std, trillium_tokio
.with_port(8080) // the default
.with_host("localhost") // the default
.with_nodelay()
.with_max_connections(Some(10000))
.without_signals()
.run(|conn: trillium::Conn| async move { conn.ok("hello") });
Socket binding
The socket binding logic is as follows:
- If a LISTEN_FD environment variable is available on
cfg(unix)
systems, that will be used, overriding host and port settings - Otherwise:
- Host will be selected from explicit configuration using
Config::with_host
or else theHOST
environment variable, or else a default of “localhost”.- On
cfg(unix)
systems only: If the host string (as set by env var or direct config) begins with.
,/
, or~
, it is interpreted to be a path, and trillium will bind to it as a unix domain socket. Port will be ignored. The socket will be deleted on clean shutdown.
- On
- Port will be selected from explicit configuration using
Config::with_port
or else thePORT
environment variable, or else a default of 8080.
- Host will be selected from explicit configuration using
Signals
On cfg(unix)
systems, SIGTERM
, SIGINT
, and SIGQUIT
are all
registered to perform a graceful shutdown on the first signal and an
immediate shutdown on a subsequent signal. This behavior may change as
trillium matures. To disable this behavior, use
Config::without_signals
.
For runtime adapter authors
In order to use this to implement a trillium server, see
trillium_server_common::ConfigExt
Implementations
Starts an async runtime and runs the provided handler with
this config in that runtime. This is the appropriate
entrypoint for applications that do not need to spawn tasks
outside of trillium’s web server. For applications that embed a
trillium server inside of an already-running async runtime, use
Config::run_async
Runs the provided handler with this config, in an
already-running runtime. This is the appropriate entrypoint
for an application that needs to spawn async tasks that are
unrelated to the trillium application. If you do not need to spawn
other tasks, Config::run
is the preferred entrypoint
Configures the server to listen on this port. The default is the PORT environment variable or 8080
Configures the server to listen on this host or ip address. The default is the HOST environment variable or “localhost”
Configures the server to NOT register for graceful-shutdown signals with the operating system. Default behavior is for the server to listen for SIGINT and SIGTERM and perform a graceful shutdown.
Configures the tcp listener to use TCP_NODELAY. See https://en.wikipedia.org/wiki/Nagle%27s_algorithm for more information on this setting.
pub fn with_acceptor<A: Acceptor<ServerType::Transport>>(
self,
acceptor: A
) -> Config<ServerType, A>
pub fn with_acceptor<A: Acceptor<ServerType::Transport>>(
self,
acceptor: A
) -> Config<ServerType, A>
Configures the tls acceptor for this server
use the specific Stopper
provided
Configures the maximum number of connections to accept. The
default is 75% of the soft rlimit_nofile (ulimit -n
) on unix
systems, and None on other sytems.
Trait Implementations
resolve a port for this application, either directly
configured, from the environmental variable PORT
, or a default
of 8080
Read more
resolve the host for this application, either directly from
configuration, from the HOST
env var, or "localhost"
Read more
use the ConfigExt::port
and ConfigExt::host
to resolve
a vec of potential socket addrs Read more
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. Read more
returns whether the server should set TCP_NODELAY on the TcpListener, if that is applicable Read more
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. Read more
waits for the last clone of the CloneCounter
in this
config to drop, indicating that all outstanding requests are
complete Read more
apply the provided handler to the transport, using
trillium_http
’s http implementation. this is the default inner
loop for most trillium servers Read more
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
. Read more
determines if the server is currently responding to more than
the maximum number of connections set by
Config::with_max_connections
. Read more
Auto Trait Implementations
impl<ServerType, AcceptorType> !RefUnwindSafe for Config<ServerType, AcceptorType>
impl<ServerType: ?Sized, AcceptorType> Send for Config<ServerType, AcceptorType> where
AcceptorType: Send,
ServerType: Send,
impl<ServerType: ?Sized, AcceptorType> Sync for Config<ServerType, AcceptorType> where
AcceptorType: Sync,
ServerType: Sync,
impl<ServerType: ?Sized, AcceptorType> Unpin for Config<ServerType, AcceptorType> where
AcceptorType: Unpin,
ServerType: Unpin,
impl<ServerType, AcceptorType> !UnwindSafe for Config<ServerType, AcceptorType>
Blanket Implementations
Mutably borrows from an owned value. Read more