Skip to content

Commit f28c149

Browse files
author
Pat Hickey
committed
handle errors from try_read_buf a bit
1 parent d009fe4 commit f28c149

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • crates/wasi/src/preview2

crates/wasi/src/preview2/tcp.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,16 @@ impl HostInputStream for HostTcpSocketInner {
8181
}
8282

8383
let mut buf = bytes::BytesMut::with_capacity(size);
84-
let n = self.stream.try_read_buf(&mut buf)?;
84+
let n = match self.stream.try_read_buf(&mut buf) {
85+
Ok(n) => n,
86+
Err(e) if e.error_kind() == std::io::ErrorKind::WouldBlock => 0,
87+
Err(_) => {
88+
// FIXME: this is a closed stream, but we need to record it for future calls to
89+
// ready
90+
return Ok((Bytes::new(), StreamState::Closed));
91+
}
92+
};
8593

86-
// TODO: how do we detect a closed stream?
8794
buf.truncate(n);
8895
Ok((buf.freeze(), StreamState::Open))
8996
}

0 commit comments

Comments
 (0)