pub struct ServiceConfig<Cfg: ServerAppConfig>(/* private fields */);Expand description
Listener and worker configuration used by ServerBuilder::configure.
Listeners are registered by name. Each worker then runs the
on_worker_start callbacks, which attach a
service to each name through ServiceRuntime::service.
Implementations§
Source§impl<Cfg: ServerAppConfig> ServiceConfig<Cfg>
impl<Cfg: ServerAppConfig> ServiceConfig<Cfg>
Sourcepub fn bind(
&self,
name: impl AsRef<str>,
addr: impl ToSocketAddrs,
) -> Result<&Self>
pub fn bind( &self, name: impl AsRef<str>, addr: impl ToSocketAddrs, ) -> Result<&Self>
Binds TCP listeners under the specified name.
A listener is created for every address resolved from addr, using
the builder’s backlog. Binding succeeds if at least one address binds.
The service for name is attached later with
ServiceRuntime::service.
Sourcepub fn listen(&self, name: impl AsRef<str>, lst: TcpListener) -> &Self
pub fn listen(&self, name: impl AsRef<str>, lst: TcpListener) -> &Self
Registers an existing TCP listener under the specified name.
The listener is switched to non-blocking mode. The service for name
is attached later with ServiceRuntime::service.
Sourcepub fn on_worker_start<F>(&self, f: F) -> &Self
pub fn on_worker_start<F>(&self, f: F) -> &Self
Registers an asynchronous worker configuration callback.
The callback runs on each worker thread while the worker creates its services, and it should attach a service to every registered name. Multiple callbacks run in registration order. An error fails the worker’s service creation. Names left without a service are logged as errors, and their connections are dropped.