about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-30 07:00:31 +0100
committerGitHub <noreply@github.com>2022-11-30 07:00:31 +0100
commitc752eaa7def39823b214cf0b9f7e7016607437ef (patch)
tree4adcc806997ab463752e213f412f2f9fd8efea35
parent0c14551fe55ff009fd1dc178e5c5463a72fa4f71 (diff)
parente598af6f2710464e20a796d0d3eba642747bcbe3 (diff)
downloadrust-c752eaa7def39823b214cf0b9f7e7016607437ef.tar.gz
rust-c752eaa7def39823b214cf0b9f7e7016607437ef.zip
Rollup merge of #104811 - haraldh:feat/wasm32_wasi_shutdown, r=joshtriplett
feat: implement TcpStream shutdown for wasm32-wasi

Signed-off-by: Harald Hoyer <harald@profian.com>
-rw-r--r--library/std/src/sys/wasi/net.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs
index 590d268c380..cf4ebba1a39 100644
--- a/library/std/src/sys/wasi/net.rs
+++ b/library/std/src/sys/wasi/net.rs
@@ -119,8 +119,14 @@ impl TcpStream {
         unsupported()
     }
 
-    pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
-        unsupported()
+    pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
+        let wasi_how = match how {
+            Shutdown::Read => wasi::SDFLAGS_RD,
+            Shutdown::Write => wasi::SDFLAGS_WR,
+            Shutdown::Both => wasi::SDFLAGS_RD | wasi::SDFLAGS_WR,
+        };
+
+        unsafe { wasi::sock_shutdown(self.socket().as_raw_fd() as _, wasi_how).map_err(err2io) }
     }
 
     pub fn duplicate(&self) -> io::Result<TcpStream> {