mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-12 17:41:22 +00:00
Make <SubstreamRef as AsyncWrite>::shutdown
imply flush (#1180)
* Make `<SubstreamRef as AsyncWrite>::shutdown` imply flush * Use try_ready * Apply suggestions from code review Co-Authored-By: Toralf Wittner <tw@dtex.org>
This commit is contained in:
committed by
Pierre Krieger
parent
69bd0dfffb
commit
e4d43030eb
@ -338,6 +338,7 @@ where
|
||||
SubstreamRef {
|
||||
muxer,
|
||||
substream: Some(substream),
|
||||
shutdown_state: ShutdownState::Shutdown,
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,6 +350,13 @@ where
|
||||
{
|
||||
muxer: P,
|
||||
substream: Option<<P::Target as StreamMuxer>::Substream>,
|
||||
shutdown_state: ShutdownState,
|
||||
}
|
||||
|
||||
enum ShutdownState {
|
||||
Shutdown,
|
||||
Flush,
|
||||
Done,
|
||||
}
|
||||
|
||||
impl<P> fmt::Debug for SubstreamRef<P>
|
||||
@ -431,8 +439,21 @@ where
|
||||
#[inline]
|
||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||
let s = self.substream.as_mut().expect("substream was empty");
|
||||
self.muxer.shutdown_substream(s).map_err(|e| e.into())?;
|
||||
Ok(Async::Ready(()))
|
||||
loop {
|
||||
match self.shutdown_state {
|
||||
ShutdownState::Shutdown => {
|
||||
try_ready!(self.muxer.shutdown_substream(s).map_err(|e| e.into()));
|
||||
self.shutdown_state = ShutdownState::Flush;
|
||||
}
|
||||
ShutdownState::Flush => {
|
||||
try_ready!(self.muxer.flush_substream(s).map_err(|e| e.into()));
|
||||
self.shutdown_state = ShutdownState::Done;
|
||||
}
|
||||
ShutdownState::Done => {
|
||||
return Ok(Async::Ready(()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Reference in New Issue
Block a user