UnixStream::poll_shutdown is not a no-op (#2245)

This commit is contained in:
Jon Gjengset
2020-02-14 12:22:29 -05:00
committed by GitHub
parent 564da5c128
commit fc65951731
2 changed files with 24 additions and 0 deletions
+1
View File
@@ -173,6 +173,7 @@ impl AsyncWrite for UnixStream {
}
fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
self.shutdown(std::net::Shutdown::Write)?;
Poll::Ready(Ok(()))
}
}
+23
View File
@@ -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(())
}