Struct ntex_server::net::ServerBuilder
source · pub struct ServerBuilder { /* private fields */ }
Expand description
Streaming service builder
This type can be used to construct an instance of net streaming server
through a
builder-like pattern.
Implementations§
source§impl ServerBuilder
impl ServerBuilder
sourcepub fn new() -> ServerBuilder
pub fn new() -> ServerBuilder
Create new Server builder instance
sourcepub fn workers(self, num: usize) -> Self
pub fn workers(self, num: usize) -> Self
Set number of workers to start.
By default server uses number of available logical cpu as workers count.
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.
By default max connections is set to a 25k per worker.
sourcepub fn stop_runtime(self) -> Self
pub fn stop_runtime(self) -> Self
Stop ntex runtime when server get dropped.
By default “stop runtime” 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 shutdown_timeout<T: Into<Millis>>(self, timeout: T) -> Self
pub fn shutdown_timeout<T: Into<Millis>>(self, timeout: T) -> Self
Timeout for graceful workers shutdown.
After receiving a stop signal, workers have this much time to finish serving requests. Workers still alive after the timeout are force dropped.
By default shutdown timeout sets to 30 seconds.
sourcepub fn status_handler<F>(self, handler: F) -> Self
pub fn status_handler<F>(self, handler: F) -> Self
Set server status handler.
Server calls this handler on every inner status update.
sourcepub fn configure<F>(self, f: F) -> Result<ServerBuilder>
pub fn configure<F>(self, f: F) -> Result<ServerBuilder>
Execute external 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 async fn configure_async<F, R>(self, f: F) -> Result<ServerBuilder>
pub async fn configure_async<F, R>(self, f: F) -> Result<ServerBuilder>
Execute external async 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 on_worker_start<F, R, E>(self, f: F) -> Self
pub fn on_worker_start<F, R, E>(self, f: F) -> Self
Register async service configuration function.
This function get called during worker runtime configuration stage. It get executed in the worker thread.
sourcepub fn bind<F, U, N, R>(self, name: N, addr: U, factory: F) -> Result<Self>where
U: ToSocketAddrs,
N: AsRef<str>,
F: Fn(Config) -> R + Send + Clone + 'static,
R: ServiceFactory<Io> + 'static,
pub fn bind<F, U, N, R>(self, name: N, addr: U, factory: F) -> Result<Self>where
U: ToSocketAddrs,
N: AsRef<str>,
F: Fn(Config) -> R + Send + Clone + 'static,
R: ServiceFactory<Io> + 'static,
Add new service to the server.
sourcepub fn bind_uds<F, U, N, R>(self, name: N, addr: U, factory: F) -> Result<Self>
pub fn bind_uds<F, U, N, R>(self, name: N, addr: U, factory: F) -> Result<Self>
Add new unix domain service to the server.
sourcepub fn listen_uds<F, N: AsRef<str>, R>(
self,
name: N,
lst: UnixListener,
factory: F,
) -> Result<Self>
pub fn listen_uds<F, N: AsRef<str>, R>( self, name: N, lst: UnixListener, factory: F, ) -> Result<Self>
Add new unix domain service to the server. Useful when running as a systemd service and a socket FD can be acquired using the systemd crate.
sourcepub fn listen<F, N: AsRef<str>, R>(
self,
name: N,
lst: TcpListener,
factory: F,
) -> Result<Self>
pub fn listen<F, N: AsRef<str>, R>( self, name: N, lst: TcpListener, factory: F, ) -> Result<Self>
Add new service to the server.
sourcepub fn set_tag<N: AsRef<str>>(self, name: N, tag: &'static str) -> Self
pub fn set_tag<N: AsRef<str>>(self, name: N, tag: &'static str) -> Self
Set io tag for named service.
sourcepub fn run(self) -> Server<Connection> ⓘ
pub fn run(self) -> Server<Connection> ⓘ
Starts processing incoming connections and return server controller.