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

Rename shutdown method on {Tcp,Unix}Stream to shutdown_std and make it private, to avoid clash with AsyncWriteExt::shutdown #3298

Merged
merged 7 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl AsyncWrite for WriteHalf<'_> {

// `poll_shutdown` on a write half shutdowns the stream in the "write" direction.
fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
self.0.shutdown(Shutdown::Write).into()
self.0.shutdown_std(Shutdown::Write).into()
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/tcp/split_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl OwnedWriteHalf {
impl Drop for OwnedWriteHalf {
fn drop(&mut self) {
if self.shutdown_on_drop {
let _ = self.inner.shutdown(Shutdown::Write);
let _ = self.inner.shutdown_std(Shutdown::Write);
}
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ impl AsyncWrite for OwnedWriteHalf {

// `poll_shutdown` on a write half shutdowns the stream in the "write" direction.
fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
let res = self.inner.shutdown(Shutdown::Write);
let res = self.inner.shutdown_std(Shutdown::Write);
if res.is_ok() {
Pin::into_inner(self).shutdown_on_drop = false;
}
Expand Down
27 changes: 4 additions & 23 deletions tokio/src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,26 +686,7 @@ impl TcpStream {
/// This function will cause all pending and future I/O on the specified
/// portions to return immediately with an appropriate value (see the
/// documentation of `Shutdown`).
///
/// # Examples
///
/// ```no_run
/// use tokio::net::TcpStream;
/// use std::error::Error;
/// use std::net::Shutdown;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn Error>> {
/// // Connect to a peer
/// let stream = TcpStream::connect("127.0.0.1:8080").await?;
///
/// // Shutdown the stream
/// stream.shutdown(Shutdown::Write)?;
///
/// Ok(())
/// }
/// ```
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
pub(super) fn shutdown_std(&self, how: Shutdown) -> io::Result<()> {
self.io.shutdown(how)
}

Expand Down Expand Up @@ -883,10 +864,10 @@ impl TcpStream {
/// this comes at the cost of a heap allocation.
///
/// **Note:** Dropping the write half will shut down the write half of the TCP
/// stream. This is equivalent to calling [`shutdown(Write)`] on the `TcpStream`.
/// stream. This is equivalent to calling [`shutdown_std(Write)`] on the `TcpStream`.
///
/// [`split`]: TcpStream::split()
/// [`shutdown(Write)`]: fn@crate::net::TcpStream::shutdown
/// [`shutdown_std(Write)`]: fn@crate::net::TcpStream::shutdown_std
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) {
split_owned(self)
}
Expand Down Expand Up @@ -980,7 +961,7 @@ impl AsyncWrite for TcpStream {
}

fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
self.shutdown(std::net::Shutdown::Write)?;
self.shutdown_std(std::net::Shutdown::Write)?;
Poll::Ready(Ok(()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl AsyncWrite for WriteHalf<'_> {
}

fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
self.0.shutdown(Shutdown::Write).into()
self.0.shutdown_std(Shutdown::Write).into()
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/unix/split_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl OwnedWriteHalf {
impl Drop for OwnedWriteHalf {
fn drop(&mut self) {
if self.shutdown_on_drop {
let _ = self.inner.shutdown(Shutdown::Write);
let _ = self.inner.shutdown_std(Shutdown::Write);
}
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl AsyncWrite for OwnedWriteHalf {

// `poll_shutdown` on a write half shutdowns the stream in the "write" direction.
fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
let res = self.inner.shutdown(Shutdown::Write);
let res = self.inner.shutdown_std(Shutdown::Write);
if res.is_ok() {
Pin::into_inner(self).shutdown_on_drop = false;
}
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl UnixStream {
/// This function will cause all pending and future I/O calls on the
/// specified portions to immediately return with an appropriate value
/// (see the documentation of `Shutdown`).
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
pub(super) fn shutdown_std(&self, how: Shutdown) -> io::Result<()> {
self.io.shutdown(how)
}

Expand All @@ -440,10 +440,10 @@ impl UnixStream {
/// this comes at the cost of a heap allocation.
///
/// **Note:** Dropping the write half will shut down the write half of the
/// stream. This is equivalent to calling [`shutdown(Write)`] on the `UnixStream`.
/// stream. This is equivalent to calling [`shutdown_std(Write)`] on the `UnixStream`.
///
/// [`split`]: Self::split()
/// [`shutdown(Write)`]: fn@Self::shutdown
/// [`shutdown_std(Write)`]: fn@Self::shutdown_std
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) {
split_owned(self)
}
Expand Down Expand Up @@ -497,7 +497,7 @@ impl AsyncWrite for UnixStream {
}

fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
self.shutdown(std::net::Shutdown::Write)?;
self.shutdown_std(std::net::Shutdown::Write)?;
Poll::Ready(Ok(()))
}
}
Expand Down