Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/muxing: Rename close to poll_close #2666

Merged
merged 3 commits into from May 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions core/CHANGELOG.md
@@ -1,6 +1,7 @@
# 0.33.0 [unreleased]

- Have methods on `Transport` take `&mut self` instead of `self`. See [PR 2529].
- Rename `StreamMuxer::close` to `StreamMuxer::poll_close`
- Remove deprecated function `StreamMuxer::is_remote_acknowledged`. See [PR 2665].

[PR 2529]: https://github.com/libp2p/rust-libp2p/pull/2529
mxinden marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 3 additions & 3 deletions core/src/either.rs
Expand Up @@ -346,10 +346,10 @@ where
}
}

fn close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match self {
EitherOutput::First(inner) => inner.close(cx).map_err(|e| e.into()),
EitherOutput::Second(inner) => inner.close(cx).map_err(|e| e.into()),
EitherOutput::First(inner) => inner.poll_close(cx).map_err(|e| e.into()),
EitherOutput::Second(inner) => inner.poll_close(cx).map_err(|e| e.into()),
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/muxing.rs
Expand Up @@ -215,7 +215,7 @@ pub trait StreamMuxer {
/// > that the remote is properly informed of the shutdown. However, apart from
/// > properly informing the remote, there is no difference between this and
/// > immediately dropping the muxer.
fn close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;

/// Flush this `StreamMuxer`.
///
Expand Down Expand Up @@ -606,8 +606,8 @@ impl StreamMuxer for StreamMuxerBox {
}

#[inline]
fn close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.close(cx)
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_close(cx)
}

#[inline]
Expand Down Expand Up @@ -747,8 +747,8 @@ where
}

#[inline]
fn close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.close(cx).map_err(|e| e.into())
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_close(cx).map_err(|e| e.into())
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion core/src/muxing/singleton.rs
Expand Up @@ -149,7 +149,7 @@ where

fn destroy_substream(&self, _: Self::Substream) {}

fn close(&self, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
// The `StreamMuxer` trait requires that `close()` implies `flush_all()`.
self.flush_all(cx)
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/util.rs
Expand Up @@ -32,7 +32,7 @@ where
loop {
match std::mem::replace(&mut self.state, CloseMuxerState::Done) {
CloseMuxerState::Close(muxer) => {
if !muxer.close(cx)?.is_ready() {
if !muxer.poll_close(cx)?.is_ready() {
self.state = CloseMuxerState::Close(muxer);
return Poll::Pending;
}
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/src/lib.rs
Expand Up @@ -169,7 +169,7 @@ where
self.io.lock().drop_stream(sub.id);
}

fn close(&self, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
self.io.lock().poll_close(cx)
}

Expand Down
2 changes: 1 addition & 1 deletion muxers/yamux/src/lib.rs
Expand Up @@ -177,7 +177,7 @@ where

fn destroy_substream(&self, _: Self::Substream) {}

fn close(&self, c: &mut Context<'_>) -> Poll<YamuxResult<()>> {
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));
Expand Down
2 changes: 1 addition & 1 deletion swarm/src/connection/pool.rs
Expand Up @@ -686,7 +686,7 @@ where
if let Err(error) = error {
self.spawn(
poll_fn(move |cx| {
if let Err(e) = ready!(muxer.close(cx)) {
if let Err(e) = ready!(muxer.poll_close(cx)) {
log::debug!(
"Failed to close connection {:?} to peer {}: {:?}",
id,
Expand Down
2 changes: 1 addition & 1 deletion swarm/src/connection/substream.rs
Expand Up @@ -211,7 +211,7 @@ where
type Output = Result<(), IoError>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.muxer.close(cx) {
match self.muxer.poll_close(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(Ok(())) => Poll::Ready(Ok(())),
Poll::Ready(Err(err)) => Poll::Ready(Err(err.into())),
Expand Down