Skip to main content

ServerConfiguration

Trait ServerConfiguration 

Source
pub trait ServerConfiguration:
    Send
    + Clone
    + 'static {
    type Item: Send + 'static;
    type Service: Service<(), Self::Item, Res = (), Error = ()> + 'static;

    // Required method
    async fn create(&self) -> Result<Self::Service>;

    // Provided methods
    fn pause(&self) { ... }
    fn resume(&self) { ... }
    fn terminate(&self) { ... }
    async fn stop(&self) { ... }
    fn incoming_cpu(&self, item: &Self::Item) -> Option<usize> { ... }
}
Expand description

Worker service configuration.

Required Associated Types§

Source

type Item: Send + 'static

Item dispatched to a worker service.

Source

type Service: Service<(), Self::Item, Res = (), Error = ()> + 'static

Service created independently for each worker.

Required Methods§

Source

async fn create(&self) -> Result<Self::Service>

Creates the service used by one worker.

Provided Methods§

Source

fn pause(&self)

Called when the server status changes from Ready to paused or unavailable.

The server is paused by Server::pause, and it is unavailable while no worker can accept items. Not called when the server stops.

Source

fn resume(&self)

Called when the server status becomes Ready.

The server is ready while it is not paused and a worker is available.

Source

fn terminate(&self)

Called when the server’s command loop exits.

This happens after a stop requested through Server::stop or a signal, graceful or not, once stop has completed.

Source

async fn stop(&self)

Performs asynchronous cleanup when the server stops.

Called once, before the workers are stopped.

Source

fn incoming_cpu(&self, item: &Self::Item) -> Option<usize>

Returns the index of the logical CPU that receives the network packets of the item, if known.

Used by LoadBalancing::IncomingCpu to send the item to the worker placed on that CPU. CPUs are numbered as in Worker::start. Network servers return the receive-side scaling (RSS) CPU of the connection on Windows, and its SO_INCOMING_CPU on Linux and Android. The default returns None.

Called on the thread that submits the item with Server::process, e.g. the accept thread of a network server. Calls are not concurrent. An item submitted while the method runs, e.g. by the method itself, is sent without its incoming CPU.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Cfg: ServerAppConfig> ServerConfiguration for StreamServer<Cfg>

Worker service factory.

Source§

type Item = Connection

Source§

type Service = StreamService