Skip to main content

ServerBuilder

Struct ServerBuilder 

Source
pub struct ServerBuilder<St = ()> { /* 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<St> ServerBuilder<St>
where St: State<St, Io> + Clone + 'static,

Source

pub fn new<F>(state: F) -> ServerBuilder<St>
where F: AsyncFn() -> Result<St, &'static str> + Send + Clone + 'static,

Create new Server builder instance.

Provided function get called during worker runtime configuration stage and must construct server state.

Source

pub fn with_default() -> ServerBuilder<St>
where St: Default,

Create new Server builder instance with default state factory.

Source

pub fn name<T: AsRef<str>>(self, name: T) -> Self

Set server name.

Name is used for worker thread name

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 stop_on_panic(self) -> Self

Stops the server when one of the workers panics.

By default, “stop on panic” is disabled.

Source

pub fn disable_signals(self) -> Self

Disable signal handling.

By default, signal handling is enabled.

Source

pub fn enable_affinity(self) -> Self

Enable cpu affinity.

By default, affinity is disabled.

Source

pub fn graceful_shutdown(self) -> Self

Graceful shutdown.

Gracefully shuts down on SIGTERM, SIGSEGV, or SIGQUIT. By default, graceful shutdown is disabled.

Source

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.

Source

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

Sets the server status handler.

The server calls this handler on every internal status update.

Source

pub async fn configure<F>(self, f: F) -> Result<Self>
where F: AsyncFn(ServiceConfig<St>) -> 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 bind<F, S, I>( self, name: impl AsRef<str>, addr: impl ToSocketAddrs, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
where F: AsyncFn(&St) -> I + Send + Clone + 'static, S: Service<St, Io> + 'static, I: IntoService<S, St, Io> + 'static, St: State<St, Io> + 'static,

Add new service to the server.

Source

pub fn bind_uds<F, I, S>( self, name: impl AsRef<str>, addr: impl AsRef<Path>, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
where F: AsyncFn(&St) -> I + Send + Clone + 'static, I: IntoService<S, St, Io> + 'static, S: Service<St, Io> + 'static, St: State<St, Io> + 'static,

Add new unix domain service to the server.

Source

pub fn listen_uds<F, I, S>( self, name: impl AsRef<str>, lst: UnixListener, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
where F: AsyncFn(&St) -> I + Send + Clone + 'static, I: IntoService<S, St, Io> + 'static, S: Service<St, Io> + 'static, St: State<St, 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, S, I>( self, name: impl AsRef<str>, lst: TcpListener, cfg: impl Into<SharedCfg>, factory: F, ) -> Result<Self>
where F: AsyncFn(&St) -> I + Send + Clone + 'static, S: Service<St, Io> + 'static, I: IntoService<S, St, Io> + 'static, St: State<St, Io> + 'static,

Add new service to the server.

Source

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

Starts processing incoming connections and return server controller.

Trait Implementations§

Source§

impl<St> Debug for ServerBuilder<St>

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§

§

impl<St = ()> !RefUnwindSafe for ServerBuilder<St>

§

impl<St = ()> !Sync for ServerBuilder<St>

§

impl<St = ()> !UnwindSafe for ServerBuilder<St>

§

impl<St> Freeze for ServerBuilder<St>
where Box<dyn StateFactory<St> + Send>: Freeze, Vec<Box<dyn FactoryService<St>>>: Freeze, PhantomData<St>: Freeze,

§

impl<St> Send for ServerBuilder<St>
where Box<dyn StateFactory<St> + Send>: Send, Vec<Box<dyn FactoryService<St>>>: Send, PhantomData<St>: Send,

§

impl<St> Unpin for ServerBuilder<St>
where Box<dyn StateFactory<St> + Send>: Unpin, Vec<Box<dyn FactoryService<St>>>: Unpin, PhantomData<St>: Unpin,

§

impl<St> UnsafeUnpin for ServerBuilder<St>
where Box<dyn StateFactory<St> + Send>: UnsafeUnpin, Vec<Box<dyn FactoryService<St>>>: UnsafeUnpin, PhantomData<St>: UnsafeUnpin,

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, 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 = !

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.