mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-23 00:00:10 +02:00
net: remove {Tcp,Unix}Stream::shutdown() (#3298)
`shutdown()` on `AsyncWrite` performs a TCP shutdown. This avoids method conflicts. Closes #3294
This commit is contained in:
@@ -171,7 +171,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,7 +253,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;
|
||||
}
|
||||
|
||||
+11
-23
@@ -56,6 +56,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>,
|
||||
}
|
||||
@@ -685,26 +692,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)
|
||||
}
|
||||
|
||||
@@ -882,10 +870,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)
|
||||
}
|
||||
@@ -979,7 +967,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(()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,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;
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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(()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user