muxers/yamux: Refactor Yamux::close to use ? (#2677)

This commit is contained in:
Thomas Eizinger 2022-05-31 15:24:03 +02:00 committed by GitHub
parent 6e1e314872
commit 3611d69e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
}