Skip to content

Commit

Permalink
Rename close to poll_close
Browse files Browse the repository at this point in the history
It is common practise to prefix functions that return a `Poll` with
`poll_`.
  • Loading branch information
thomaseizinger committed May 23, 2022
1 parent ef2afcd commit f2e4dcd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
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`

[PR 2529]: https://github.com/libp2p/rust-libp2p/pull/2529

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 @@ -226,7 +226,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 @@ -617,8 +617,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 @@ -758,8 +758,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 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

0 comments on commit f2e4dcd

Please sign in to comment.