Skip to content

Commit 7e7f389

Browse files
authored
Rollup merge of #104811 - haraldh:feat/wasm32_wasi_shutdown, r=joshtriplett
feat: implement TcpStream shutdown for wasm32-wasi Signed-off-by: Harald Hoyer <[email protected]>
2 parents 6cd8e14 + ca57811 commit 7e7f389

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

std/src/sys/wasi/net.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ impl TcpStream {
119119
unsupported()
120120
}
121121

122-
pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
123-
unsupported()
122+
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
123+
let wasi_how = match how {
124+
Shutdown::Read => wasi::SDFLAGS_RD,
125+
Shutdown::Write => wasi::SDFLAGS_WR,
126+
Shutdown::Both => wasi::SDFLAGS_RD | wasi::SDFLAGS_WR,
127+
};
128+
129+
unsafe { wasi::sock_shutdown(self.socket().as_raw_fd() as _, wasi_how).map_err(err2io) }
124130
}
125131

126132
pub fn duplicate(&self) -> io::Result<TcpStream> {

0 commit comments

Comments
 (0)