mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-01 20:21:21 +00:00
muxers/yamux: Refactor Yamux::close
to use ?
(#2677)
This commit is contained in:
parent
6e1e314872
commit
3611d69e09
@ -31,7 +31,7 @@ use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent};
|
||||
use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||
use parking_lot::Mutex;
|
||||
use std::{
|
||||
fmt, io, iter,
|
||||
fmt, io, iter, mem,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
@ -179,16 +179,21 @@ where
|
||||
|
||||
fn poll_close(&self, c: &mut Context<'_>) -> Poll<YamuxResult<()>> {
|
||||
let mut inner = self.0.lock();
|
||||
if let std::task::Poll::Ready(x) = Pin::new(&mut inner.control).poll_close(c) {
|
||||
return Poll::Ready(x.map_err(YamuxError));
|
||||
|
||||
if let Poll::Ready(()) = Pin::new(&mut inner.control)
|
||||
.poll_close(c)
|
||||
.map_err(YamuxError)?
|
||||
{
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
while let std::task::Poll::Ready(x) = inner.incoming.poll_next_unpin(c) {
|
||||
match x {
|
||||
Some(Ok(_)) => {} // drop inbound stream
|
||||
Some(Err(e)) => return Poll::Ready(Err(e)),
|
||||
|
||||
while let Poll::Ready(maybe_inbound_stream) = inner.incoming.poll_next_unpin(c)? {
|
||||
match maybe_inbound_stream {
|
||||
Some(inbound_stream) => mem::drop(inbound_stream),
|
||||
None => return Poll::Ready(Ok(())),
|
||||
}
|
||||
}
|
||||
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user