Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

wasi: allow zero-length writes on tcp streams (#15186)

Xia Chao4182ebadb18e
diff --git a/crates/wasi/src/p2/tcp.rs b/crates/wasi/src/p2/tcp.rs
index 675701b99c..e6158f48da 100644
--- a/crates/wasi/src/p2/tcp.rs
+++ b/crates/wasi/src/p2/tcp.rs
@@ -181,12 +181,15 @@ impl WriteState {
}
fn write(&mut self, mut bytes: bytes::Bytes) -> StreamResult<()> {
+ if bytes.is_empty() {
+ return match self {
+ WriteState::Closed(e) => Err(e.clone().into()),
+ _ => Ok(()),
+ };
+ }
+
let mut stream = match self {
WriteState::Ready(_, permit) if bytes.len() <= *permit => {
- if bytes.is_empty() {
- return Ok(());
- }
-
let WriteState::Ready(stream, _) = self.take() else {
unreachable!()
};