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 all 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
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/split.rs
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
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
34 changes: 11 additions & 23 deletions tokio/src/net/tcp/stream.rs
Expand Up @@ -57,6 +57,13 @@ cfg_net! {
///
/// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
///
/// To shut down the stream in the write direction, you can call the
/// [`shutdown()`] method. This will cause the other peer to receive a read of
/// length 0, indicating that no more data will be sent. This only closes
/// the stream in one direction.
///
/// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
pub struct TcpStream {
io: PollEvented<mio::net::TcpStream>,
}
Expand Down Expand Up @@ -686,26 +693,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 +871,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()`] on the `TcpStream`.
///
/// [`split`]: TcpStream::split()
/// [`shutdown(Write)`]: fn@crate::net::TcpStream::shutdown
/// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) {
split_owned(self)
}
Expand Down Expand Up @@ -980,7 +968,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
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
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
15 changes: 11 additions & 4 deletions tokio/src/net/unix/stream.rs
Expand Up @@ -21,6 +21,13 @@ cfg_net_unix! {
/// This socket can be connected directly with `UnixStream::connect` or accepted
/// from a listener with `UnixListener::incoming`. Additionally, a pair of
/// anonymous Unix sockets can be created with `UnixStream::pair`.
///
/// To shut down the stream in the write direction, you can call the
/// [`shutdown()`] method. This will cause the other peer to receive a read of
/// length 0, indicating that no more data will be sent. This only closes
/// the stream in one direction.
///
/// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
pub struct UnixStream {
io: PollEvented<mio::net::UnixStream>,
}
Expand Down Expand Up @@ -415,7 +422,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 +447,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()`] on the `UnixStream`.
///
/// [`split`]: Self::split()
/// [`shutdown(Write)`]: fn@Self::shutdown
/// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) {
split_owned(self)
}
Expand Down Expand Up @@ -497,7 +504,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