pub struct ServerBuilder<Cfg = NoConfig> { /* private fields */ }Expand description
Builder for a network server.
Register listeners and their service factories, configure the worker pool,
and call run to start the server.
Implementations§
Source§impl<Cfg> ServerBuilder<Cfg>where
Cfg: ServerAppConfig,
impl<Cfg> ServerBuilder<Cfg>where
Cfg: ServerAppConfig,
Sourcepub fn new(cfg: Cfg) -> ServerBuilder<Cfg>
pub fn new(cfg: Cfg) -> ServerBuilder<Cfg>
Creates a server builder with the specified application configuration.
Sourcepub fn name<T: AsRef<str>>(self, name: T) -> Self
pub fn name<T: AsRef<str>>(self, name: T) -> Self
Sets the server name.
The name is also used for worker threads.
Sourcepub fn workers(self, num: usize) -> Self
pub fn workers(self, num: usize) -> Self
Sets the number of worker threads to start.
By default, the server uses the number of available logical CPUs.
Sourcepub fn backlog(self, num: i32) -> Self
pub fn backlog(self, num: i32) -> Self
Set the maximum number of pending connections.
This refers to the number of clients that can be waiting to be served. Exceeding this number results in the client getting an error when attempting to connect. It should only affect servers under significant load.
Generally set in the 64-2048 range. Default value is 2048.
This method should be called before bind() method call.
Sourcepub fn maxconn(self, num: usize) -> Self
pub fn maxconn(self, num: usize) -> Self
Sets the maximum per-worker number of concurrent connections.
All socket listeners will stop accepting connections when this limit is reached for each worker.
The default is 25,600 connections per worker.
Sourcepub fn stop_runtime(self) -> Self
pub fn stop_runtime(self) -> Self
Stops the current ntex runtime when the server is dropped.
By default “stop runtime” is disabled.
Sourcepub fn stop_on_panic(self) -> Self
pub fn stop_on_panic(self) -> Self
Stops the server when one of the workers panics.
By default, “stop on panic” is disabled.
Sourcepub fn disable_signals(self) -> Self
pub fn disable_signals(self) -> Self
Disable signal handling.
By default, signal handling is enabled.
Sourcepub fn enable_affinity(self) -> Self
pub fn enable_affinity(self) -> Self
Enables CPU affinity for worker threads.
By default, affinity is disabled.
Sourcepub fn graceful_shutdown(self) -> Self
pub fn graceful_shutdown(self) -> Self
Graceful shutdown.
Gracefully shuts down on SIGSEGV or SIGQUIT and app panics. Graceful shutdown is always enabled for SIGTERM. By default, it is disabled for SIGSEGV and SIGQUIT and panics.
Sourcepub fn shutdown_timeout<T: Into<Millis>>(self, timeout: T) -> Self
pub fn shutdown_timeout<T: Into<Millis>>(self, timeout: T) -> Self
Timeout for graceful worker shutdown.
After receiving a stop signal, workers have this much time to finish serving requests. Workers that are still alive after the timeout are forcefully dropped.
By default, the shutdown timeout is set to 30 seconds.
Sourcepub fn status_handler<F>(self, handler: F) -> Self
pub fn status_handler<F>(self, handler: F) -> Self
Sets the server status handler.
The server calls this handler on every internal status update.
Sourcepub async fn configure<F>(self, f: F) -> Result<Self>
pub async fn configure<F>(self, f: F) -> Result<Self>
Executes asynchronous configuration as part of the server building process.
This function is useful for moving parts of configuration to a different module or even library.
Sourcepub fn bind<F, S, I>(
self,
name: impl AsRef<str>,
addr: impl ToSocketAddrs,
cfg: impl Into<SharedCfg>,
factory: F,
) -> Result<Self>
pub fn bind<F, S, I>( self, name: impl AsRef<str>, addr: impl ToSocketAddrs, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
Binds TCP listeners and registers a service factory.
Sourcepub fn bind_uds<F, I, S>(
self,
name: impl AsRef<str>,
addr: impl AsRef<Path>,
cfg: impl Into<SharedCfg>,
factory: F,
) -> Result<Self>
pub fn bind_uds<F, I, S>( self, name: impl AsRef<str>, addr: impl AsRef<Path>, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
Binds a Unix domain socket and registers a service factory.
Sourcepub fn listen_uds<F, I, S>(
self,
name: impl AsRef<str>,
lst: UnixListener,
cfg: impl Into<SharedCfg>,
factory: F,
) -> Result<Self>
pub fn listen_uds<F, I, S>( self, name: impl AsRef<str>, lst: UnixListener, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
Registers a service factory for an existing Unix domain listener.
This is useful for socket activation, including listeners acquired through systemd.
Sourcepub fn listen<F, S, I>(
self,
name: impl AsRef<str>,
lst: TcpListener,
cfg: impl Into<SharedCfg>,
factory: F,
) -> Result<Self>
pub fn listen<F, S, I>( self, name: impl AsRef<str>, lst: TcpListener, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
Registers a service factory for an existing TCP listener.
Sourcepub fn run(self) -> Server<Connection> ⓘ
pub fn run(self) -> Server<Connection> ⓘ
Starts processing incoming connections and returns a server controller.