Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fd_write: Flush on every write to a file #3820

Merged
merged 4 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/wasi/src/syscalls/wasi/fd_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ fn fd_write_internal<M: MemorySize>(
break;
}
}
if is_stdio {
handle.flush().await.map_err(map_io_err)?;
}
Ok(written)
}
)?
Expand Down
8 changes: 4 additions & 4 deletions lib/wasi/tests/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ async fn test_stdout() {
(export "memory" (memory 0))

;; Write 'hello world\n' to memory at an offset of 8 bytes
;; Note the trailing newline which is required for the text to appear
(data (i32.const 8) "hello world\n")
;; No trailing newline is required since all stdio writes are flushing
(data (i32.const 8) "hello world")

(func $main (export "_start")
;; Creating a new io vector within linear memory
(i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string
(i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string
(i32.store (i32.const 4) (i32.const 11)) ;; iov.iov_len - The length of the 'hello world\n' string

(call $fd_write
(i32.const 1) ;; file_descriptor - 1 for stdout
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn test_stdout() {
let mut stdout_str = String::new();
stdout_rx.read_to_string(&mut stdout_str).await.unwrap();
let stdout_as_str = stdout_str.as_str();
assert_eq!(stdout_as_str, "hello world\n");
assert_eq!(stdout_as_str, "hello world");
}

async fn test_env() {
Expand Down