Skip to content

Commit

Permalink
handle errors from try_read_buf a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Hickey committed Aug 26, 2023
1 parent d009fe4 commit 98db3c1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/wasi/src/preview2/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ impl HostInputStream for HostTcpSocketInner {
}

let mut buf = bytes::BytesMut::with_capacity(size);
let n = self.stream.try_read_buf(&mut buf)?;
let n = match self.stream.try_read_buf(&mut buf) {
Ok(n) => n,
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => 0,
Err(_) => {
// FIXME: this is a closed stream, but we need to record it for future calls to
// ready
return Ok((bytes::Bytes::new(), StreamState::Closed));
}
};

// TODO: how do we detect a closed stream?
buf.truncate(n);
Ok((buf.freeze(), StreamState::Open))
}
Expand Down

0 comments on commit 98db3c1

Please sign in to comment.