pub struct ConnectionChannel<StateType: Debug> { /* private fields */ }
Expand description
The abstraction for handling server connections – here, the connections are
provided through a Stream
instead of through the TCP/IP API directly. This enables
the “Protocol Stack Composition” pattern, as already existing connections may be also
added to the Stream
(in addition to fresh incoming ones).
When the end-of-stream is reached (possibly due to a “server shutdown” request),
the Stream
will return None
.
Implementations§
Source§impl<StateType: Debug> ConnectionChannel<StateType>
impl<StateType: Debug> ConnectionChannel<StateType>
Sourcepub fn receiver(&mut self) -> Option<Receiver<SocketConnection<StateType>>>
pub fn 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().
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(
&self,
socket_connection: SocketConnection<StateType>,
) -> Result<(), ReceiverDroppedErr<SocketConnection<StateType>>>
pub async fn feed( &self, socket_connection: SocketConnection<StateType>, ) -> Result<(), ReceiverDroppedErr<SocketConnection<StateType>>>
Delivers connection
to the receiver obtained via a call to Self::receiver(),
blocking if there are previous connections awaiting delivery
Sourcepub fn clone_sender(&self) -> Sender<SocketConnection<StateType>>
pub fn clone_sender(&self) -> Sender<SocketConnection<StateType>>
Returns a cloned version of the sender.
Notice this method should be considered “advanced”, as keeping
a cloned sender will prevent the channel from shutting down,
rendering Self::close() useless – currently there is no way
for close()
to detect this situation.