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

source

pub fn new() -> ServerBuilder

Create new Server builder instance

source

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.

source

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.

source

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.

source

pub fn stop_runtime(self) -> Self

Stop ntex runtime when server get dropped.

By default “stop runtime” is disabled.

source

pub fn disable_signals(self) -> Self

Disable signal handling.

By default signal handling is enabled.

source

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.

source

pub fn status_handler<F>(self, handler: F) -> Self
where F: FnMut(ServerStatus) + Send + 'static,

Set server status handler.

Server calls this handler on every inner status update.

source

pub fn configure<F>(self, f: F) -> Result<ServerBuilder>
where F: Fn(&mut ServiceConfig) -> Result<()>,

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.

source

pub async fn configure_async<F, R>(self, f: F) -> Result<ServerBuilder>
where F: Fn(ServiceConfig) -> R, R: Future<Output = Result<()>>,

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.

source

pub fn on_worker_start<F, R, E>(self, f: F) -> Self
where F: Fn() -> R + Send + Clone + 'static, R: Future<Output = Result<(), E>> + 'static, E: Display + 'static,

Register async service configuration function.

This function get called during worker runtime configuration stage. It get executed in the worker thread.

source

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.

source

pub fn bind_uds<F, U, N, R>(self, name: N, addr: U, factory: F) -> Result<Self>
where N: AsRef<str>, U: AsRef<Path>, F: Fn(Config) -> R + Send + Clone + 'static, R: ServiceFactory<Io> + 'static,

Add new unix domain service to the server.

source

pub fn listen_uds<F, N: AsRef<str>, R>( self, name: N, lst: UnixListener, factory: F, ) -> Result<Self>
where F: Fn(Config) -> R + Send + Clone + 'static, R: ServiceFactory<Io> + 'static,

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.

source

pub fn listen<F, N: AsRef<str>, R>( self, name: N, lst: TcpListener, factory: F, ) -> Result<Self>
where F: Fn(Config) -> R + Send + Clone + 'static, R: ServiceFactory<Io> + 'static,

Add new service to the server.

source

pub fn set_tag<N: AsRef<str>>(self, name: N, tag: &'static str) -> Self

Set io tag for named service.

source

pub fn run(self) -> Server<Connection>

Starts processing incoming connections and return server controller.

Trait Implementations§

source§

impl Debug for ServerBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ServerBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more