summaryrefslogtreecommitdiffstats
path: root/tokio/src/net/tcp
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-07-12 19:25:58 -0700
committerGitHub <noreply@github.com>2020-07-12 19:25:58 -0700
commit98e78314794607d0b402d5e45c66e3b8e38b819c (patch)
treebbfd7d0d84cdd4fc58fe7adbdf5758b1c4aaf8e6 /tokio/src/net/tcp
parent8411a6945f2d4711a9422dfd4d3362e08b6e8f99 (diff)
net: fix OwnedWriteHalf behavior on drop (#2597)
Previously, dropping the Write handle would issue a `shutdown(Both)`. However, shutting down the read half is not portable and not the correct action to take. This changes the behavior of OwnedWriteHalf to only perform a `shutdown(Write)` on drop.
Diffstat (limited to 'tokio/src/net/tcp')
-rw-r--r--tokio/src/net/tcp/split_owned.rs9
-rw-r--r--tokio/src/net/tcp/stream.rs3
2 files changed, 6 insertions, 6 deletions
diff --git a/tokio/src/net/tcp/split_owned.rs b/tokio/src/net/tcp/split_owned.rs
index ff82f6ed..3f6ee33f 100644
--- a/tokio/src/net/tcp/split_owned.rs
+++ b/tokio/src/net/tcp/split_owned.rs
@@ -40,7 +40,7 @@ pub struct OwnedReadHalf {
/// Note that in the [`AsyncWrite`] implemenation of this type, [`poll_shutdown`] will
/// shut down the TCP stream in the write direction.
///
-/// Dropping the write half will close the TCP stream in both directions.
+/// Dropping the write half will shutdown the write half of the TCP stream.
///
/// Writing to an `OwnedWriteHalf` is usually done using the convenience methods found
/// on the [`AsyncWriteExt`] trait. Examples import this trait through [the prelude].
@@ -209,9 +209,8 @@ impl OwnedWriteHalf {
pub fn reunite(self, other: OwnedReadHalf) -> Result<TcpStream, ReuniteError> {
reunite(other, self)
}
- /// Destroy the write half, but don't close the stream until the read half
- /// is dropped. If the read half has already been dropped, this closes the
- /// stream.
+
+ /// Drop the write half, but don't issue a TCP shutdown.
pub fn forget(mut self) {
self.shutdown_on_drop = false;
drop(self);
@@ -221,7 +220,7 @@ impl OwnedWriteHalf {
impl Drop for OwnedWriteHalf {
fn drop(&mut self) {
if self.shutdown_on_drop {
- let _ = self.inner.shutdown(Shutdown::Both);
+ let _ = self.inner.shutdown(Shutdown::Write);
}
}
}
diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs
index 92c7c84e..319ef72e 100644
--- a/tokio/src/net/tcp/stream.rs
+++ b/tokio/src/net/tcp/stream.rs
@@ -652,7 +652,8 @@ impl TcpStream {
/// Unlike [`split`], the owned halves can be moved to separate tasks, however
/// this comes at the cost of a heap allocation.
///
- /// **Note:** Dropping the write half will close the TCP stream in both directions.
+ /// **Note::** Dropping the write half will shutdown the write half of the TCP
+ /// stream. This is equivalent to calling `shutdown(Write)` on the `TcpStream`.
///
/// [`split`]: TcpStream::split()
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf) {