From 00a34557f078e858a5aad0974dd4697d67b3b5af Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 12:05:38 +0100 Subject: [PATCH 1/7] Rename TcpStream::shutdown and make it private to avoid clash with AsyncWriteExt Signed-off-by: Arve Knudsen --- tokio/src/net/tcp/split.rs | 2 +- tokio/src/net/tcp/split_owned.rs | 4 ++-- tokio/src/net/tcp/stream.rs | 23 ++--------------------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/tokio/src/net/tcp/split.rs b/tokio/src/net/tcp/split.rs index 296b469d4a3..605029c759d 100644 --- a/tokio/src/net/tcp/split.rs +++ b/tokio/src/net/tcp/split.rs @@ -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> { - self.0.shutdown(Shutdown::Write).into() + self.0.shutdown_std(Shutdown::Write).into() } } diff --git a/tokio/src/net/tcp/split_owned.rs b/tokio/src/net/tcp/split_owned.rs index 725d7411ea0..cd66903a7a1 100644 --- a/tokio/src/net/tcp/split_owned.rs +++ b/tokio/src/net/tcp/split_owned.rs @@ -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); } } } @@ -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> { - 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; } diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 56948ffa66e..1c5f42e8da0 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -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> { - /// // 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) } @@ -980,7 +961,7 @@ impl AsyncWrite for TcpStream { } fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - self.shutdown(std::net::Shutdown::Write)?; + self.shutdown_std(std::net::Shutdown::Write)?; Poll::Ready(Ok(())) } } From 07f6a40c1e143b62318735953a5a37a53ce87836 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 12:09:26 +0100 Subject: [PATCH 2/7] Rename UnixStream::shutdown and make it private to avoid clash with AsyncWriteExt Signed-off-by: Arve Knudsen --- tokio/src/net/unix/split.rs | 2 +- tokio/src/net/unix/split_owned.rs | 4 ++-- tokio/src/net/unix/stream.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tokio/src/net/unix/split.rs b/tokio/src/net/unix/split.rs index af9c762494e..c9fa94d9176 100644 --- a/tokio/src/net/unix/split.rs +++ b/tokio/src/net/unix/split.rs @@ -85,7 +85,7 @@ impl AsyncWrite for WriteHalf<'_> { } fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - self.0.shutdown(Shutdown::Write).into() + self.0.shutdown_std(Shutdown::Write).into() } } diff --git a/tokio/src/net/unix/split_owned.rs b/tokio/src/net/unix/split_owned.rs index 5f0a2593d01..f121c0a711e 100644 --- a/tokio/src/net/unix/split_owned.rs +++ b/tokio/src/net/unix/split_owned.rs @@ -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); } } } @@ -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> { - 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; } diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index e80c9217af2..5c07e2c77af 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -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) } @@ -497,7 +497,7 @@ impl AsyncWrite for UnixStream { } fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - self.shutdown(std::net::Shutdown::Write)?; + self.shutdown_std(std::net::Shutdown::Write)?; Poll::Ready(Ok(())) } } From 151ffe539c4bbad1ecb318b96ef8ce4b7220a930 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 12:14:18 +0100 Subject: [PATCH 3/7] Fix doc references Signed-off-by: Arve Knudsen --- tokio/src/net/tcp/stream.rs | 4 ++-- tokio/src/net/unix/stream.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 1c5f42e8da0..51d94c7dd5a 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -864,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) } diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 5c07e2c77af..f94337dadff 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -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) } From 909845fcbfa881bd9a0e05531be35b8213fbe138 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 12:29:56 +0100 Subject: [PATCH 4/7] Fix docs Signed-off-by: Arve Knudsen --- tokio/src/net/tcp/stream.rs | 4 ++-- tokio/src/net/unix/stream.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 51d94c7dd5a..52fee4733b3 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -864,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_std(Write)`] on the `TcpStream`. + /// stream. This is equivalent to calling [`shutdown()`] on the `TcpStream`. /// /// [`split`]: TcpStream::split() - /// [`shutdown_std(Write)`]: fn@crate::net::TcpStream::shutdown_std + /// [`shutdown()`]: fn@crate::io::util::AsyncWriteExt::shutdown pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) { split_owned(self) } diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index f94337dadff..4abae460635 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -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_std(Write)`] on the `UnixStream`. + /// stream. This is equivalent to calling [`shutdown()`] on the `UnixStream`. /// /// [`split`]: Self::split() - /// [`shutdown_std(Write)`]: fn@Self::shutdown_std + /// [`shutdown()`]: fn@crate::io::util::AsyncWriteExt::shutdown pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) { split_owned(self) } From 240a51f8b53d4ea07f5315877855418a65b110a3 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 12:37:58 +0100 Subject: [PATCH 5/7] Add notes on shutdown usage Signed-off-by: Arve Knudsen --- tokio/src/net/tcp/stream.rs | 9 ++++++++- tokio/src/net/unix/stream.rs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 52fee4733b3..55c5e05aca3 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -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 EOF, indicating that no more data has been sent. This only closes + /// the stream in one direction. + /// + /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown pub struct TcpStream { io: PollEvented, } @@ -867,7 +874,7 @@ impl TcpStream { /// stream. This is equivalent to calling [`shutdown()`] on the `TcpStream`. /// /// [`split`]: TcpStream::split() - /// [`shutdown()`]: fn@crate::io::util::AsyncWriteExt::shutdown + /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) { split_owned(self) } diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 4abae460635..1ede1004077 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -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 EOF, indicating that no more data has been sent. This only closes + /// the stream in one direction. + /// + /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown pub struct UnixStream { io: PollEvented, } @@ -443,7 +450,7 @@ impl UnixStream { /// stream. This is equivalent to calling [`shutdown()`] on the `UnixStream`. /// /// [`split`]: Self::split() - /// [`shutdown()`]: fn@crate::io::util::AsyncWriteExt::shutdown + /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) { split_owned(self) } From 5c36d657a103d58e236e7646cb7b10087ca0694b Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 12:39:18 +0100 Subject: [PATCH 6/7] Fix formatting Signed-off-by: Arve Knudsen --- tokio/src/net/tcp/stream.rs | 2 +- tokio/src/net/unix/stream.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 55c5e05aca3..16ddd7ff135 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -58,7 +58,7 @@ 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 + /// 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 EOF, indicating that no more data has been sent. This only closes /// the stream in one direction. diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 1ede1004077..59f1fe9b479 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -22,7 +22,7 @@ cfg_net_unix! { /// 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 + /// 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 EOF, indicating that no more data has been sent. This only closes /// the stream in one direction. From 72cb4c2d49f19eea81cf68b6cf6565bff45e5a58 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 19 Dec 2020 13:01:19 +0100 Subject: [PATCH 7/7] Update shutdown notes Signed-off-by: Arve Knudsen --- tokio/src/net/tcp/stream.rs | 2 +- tokio/src/net/unix/stream.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 16ddd7ff135..5239fce4046 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -60,7 +60,7 @@ cfg_net! { /// /// 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 EOF, indicating that no more data has been sent. This only closes + /// length 0, indicating that no more data will be sent. This only closes /// the stream in one direction. /// /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 59f1fe9b479..886d78f62ed 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -24,7 +24,7 @@ cfg_net_unix! { /// /// 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 EOF, indicating that no more data has been sent. This only closes + /// length 0, indicating that no more data will be sent. This only closes /// the stream in one direction. /// /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown