pub struct Server { /* private fields */ }Expand description
Stateful owner of station admission, registration, command dispatch, and event correlation.
Construction is inert: callers must poll Self::run. The server owns its
listener or injected-ingress receiver and all registered session routing;
integration code normally retains only the returned ServerHandle and
event receiver after spawning the run future. Dropping the Server future
directly is abrupt, so normal shutdown should use ServerHandle::shutdown
and then await run.
Implementations§
Source§impl Server
impl Server
Sourcepub async fn bind(
config: ServerConfig,
definitions: impl IntoIterator<Item = DeviceDefinition>,
) -> Result<(Self, ServerHandle, Receiver<Event>), ServerError>
pub async fn bind( config: ServerConfig, definitions: impl IntoIterator<Item = DeviceDefinition>, ) -> Result<(Self, ServerHandle, Receiver<Event>), ServerError>
Bind the configured plain TCP endpoint and construct a server.
The returned tuple contains the inert server, its cloneable command
handle, and the sole event receiver. Call Self::local_addr after
construction when config.bind used port zero, then spawn or await
Self::run. This constructor classifies every accepted connection as
StationTransport::Clear. Use Self::with_ingress when transport
negotiation or multiple listeners are owned elsewhere.
Sourcepub fn with_ingress(
config: ServerConfig,
definitions: impl IntoIterator<Item = DeviceDefinition>,
) -> Result<(Self, ServerHandle, Receiver<Event>, ServerIngress), ServerError>
pub fn with_ingress( config: ServerConfig, definitions: impl IntoIterator<Item = DeviceDefinition>, ) -> Result<(Self, ServerHandle, Receiver<Event>, ServerIngress), ServerError>
Construct a server whose ready station streams are supplied externally.
The additional ServerIngress value is cloned by clear and secure
listener tasks. Each task completes its transport setup, preserves the
accepted peer and local socket addresses, and submits the stream with an
accurate StationTransport classification. The returned server has no
bound listener, so Self::local_addr is unavailable.
Sourcepub fn local_addr(&self) -> Result<SocketAddr, ServerError>
pub fn local_addr(&self) -> Result<SocketAddr, ServerError>
Return the concrete address owned by Self::bind.
This exposes an operating-system-assigned port when the requested bind
address used port zero. Servers created by Self::with_ingress return
ServerError::InvalidConfig because listener addresses belong to the
external transport owner.
Sourcepub async fn run(self) -> Result<(), ServerError>
pub async fn run(self) -> Result<(), ServerError>
Drive admission, command dispatch, reconfiguration, and shutdown.
This consuming future must be polled exactly once. It accepts plain
sockets owned by Self::bind and streams submitted through
ServerIngress, starts an independent session task for each, and
serializes server-wide commands. It returns normally after an explicit
shutdown request or after every ServerHandle is dropped; before
returning it asks each registered session to disconnect. Listener or
server-level I/O failures are returned as ServerError, while an
individual session failure is emitted as Event::SessionError.