From fc65951731506ba4bbbc08eed256b5e8b0d46655 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 14 Feb 2020 12:22:29 -0500 Subject: [PATCH] UnixStream::poll_shutdown is not a no-op (#2245) --- tokio/src/net/unix/stream.rs | 1 + tokio/tests/uds_stream.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index c21e71e34..1ce9c863f 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -173,6 +173,7 @@ impl AsyncWrite for UnixStream { } fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + self.shutdown(std::net::Shutdown::Write)?; Poll::Ready(Ok(())) } } diff --git a/tokio/tests/uds_stream.rs b/tokio/tests/uds_stream.rs index 15760e22a..29f118a2d 100644 --- a/tokio/tests/uds_stream.rs +++ b/tokio/tests/uds_stream.rs @@ -33,3 +33,26 @@ async fn accept_read_write() -> std::io::Result<()> { assert_eq!(len, 0); Ok(()) } + +#[tokio::test] +async fn shutdown() -> std::io::Result<()> { + let dir = tempfile::Builder::new() + .prefix("tokio-uds-tests") + .tempdir() + .unwrap(); + let sock_path = dir.path().join("connect.sock"); + + let mut listener = UnixListener::bind(&sock_path)?; + + let accept = listener.accept(); + let connect = UnixStream::connect(&sock_path); + let ((mut server, _), mut client) = try_join(accept, connect).await?; + + // Shut down the client + AsyncWriteExt::shutdown(&mut client).await?; + // Read from the server should return 0 to indicate the channel has been closed. + let mut buf = [0u8; 1]; + let n = server.read(&mut buf).await?; + assert_eq!(n, 0); + Ok(()) +}