pub struct ServerConnectionHandler<StateType: Debug + Clone + Send + 'static> { /* private fields */ }
Expand description
Abstracts out, from servers, the connection handling so to enable the “Protocol Stack Composition” pattern:
Binds to a network listening interface and port and starts a network event loop for accepting connections,
supplying them to an internal ConnectionChannel (while also allowing manually fed connections).
Implementations§
Source§impl<StateType: Debug + Clone + Send + 'static> ServerConnectionHandler<StateType>
impl<StateType: Debug + Clone + Send + 'static> ServerConnectionHandler<StateType>
Sourcepub async fn new(
listening_interface: &str,
listening_port: u16,
connection_initial_state: StateType,
) -> Result<Self, Box<dyn Error + Sync + Send>>
pub async fn new( listening_interface: &str, listening_port: u16, connection_initial_state: StateType, ) -> Result<Self, Box<dyn Error + Sync + Send>>
Creates a new instance of a server, binding to the specified listening_interface
and listening_port
.
Incoming connections are [feed()] as they arrive – but you can also do so manually, by calling the mentioned method.
Sourcepub fn connection_receiver(
&mut self,
) -> Option<Receiver<SocketConnection<StateType>>>
pub fn connection_receiver( &mut self, ) -> Option<Receiver<SocketConnection<StateType>>>
Consumes and returns the tokio::sync::mpsc::Receiver
which will be able to
provide connections previously sent through Self::feed_connection().
The receiver blocks while there are no connections available and
yields None
if self
is dropped – meaning no more connections
will be feed through the channel.
Sourcepub async fn feed_connection(
&self,
socket_connection: SocketConnection<StateType>,
) -> Result<(), ReceiverDroppedErr<SocketConnection<StateType>>>
pub async fn feed_connection( &self, socket_connection: SocketConnection<StateType>, ) -> Result<(), ReceiverDroppedErr<SocketConnection<StateType>>>
Delivers connection
to the receiver obtained via a call to Self::connection_receiver(),
blocking if there are previous connections awaiting delivery
Sourcepub async fn shutdown(self)
pub async fn shutdown(self)
“Shutdown” the connection listener for this server, releasing the bind to the listening interface and port
and bailing out from the network event loop.
Any consumers using Self::connection_receiver() will be notified with a None
last element.