diff --git a/crates/api/c-examples/wasm-c-api b/crates/api/c-examples/wasm-c-api new file mode 160000 index 0000000000..d9a80099d4 --- /dev/null +++ b/crates/api/c-examples/wasm-c-api @@ -0,0 +1 @@ +Subproject commit d9a80099d496b5cdba6f3fe8fc77586e0e505ddc diff --git a/crates/wasi-common/WASI b/crates/wasi-common/WASI new file mode 160000 index 0000000000..04d4eba571 --- /dev/null +++ b/crates/wasi-common/WASI @@ -0,0 +1 @@ +Subproject commit 04d4eba571dc1d6fe9ab129ea9343911bcc256dc diff --git a/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs b/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs index 16c1a58586..1403e2f4d5 100644 --- a/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs @@ -24,7 +24,6 @@ struct StdinPoll { enum PollState { Ready, - Closed, NotReady, // it's not ready, but we didn't wait TimedOut, // it's not ready and a timeout has occurred Error(Error), @@ -74,9 +73,12 @@ impl StdinPoll { use std::io::BufRead; loop { request_rx.recv().expect("request_rx channel closed"); - let resp = match std::io::stdin().lock().fill_buf().map(|s| !s.is_empty()) { - Ok(true) => PollState::Ready, - Ok(false) => PollState::Closed, + // If `fill_buf` returns any slice, then it means that either + // (a) there some data in stdout, if it's non-empty + // (b) EOF was received, if it's empty + // Linux returns `POLLIN` in both cases, and we imitate this behavior. + let resp = match std::io::stdin().lock().fill_buf() { + Ok(_) => PollState::Ready, Err(e) => PollState::Error(e.into()), }; notify_tx.send(resp).expect("notify_tx channel closed"); @@ -187,20 +189,6 @@ fn make_timeout_event(timeout: &ClockEventData) -> wasi::__wasi_event_t { } } -fn make_hangup_event(fd_event: &FdEventData) -> wasi::__wasi_event_t { - wasi::__wasi_event_t { - userdata: fd_event.userdata, - r#type: fd_event.r#type, - error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, - }, - } -} - fn handle_timeout( timeout_event: ClockEventData, timeout: Duration, @@ -215,11 +203,6 @@ fn handle_timeout_event(timeout_event: ClockEventData, events: &mut Vec) { - let new_event = make_hangup_event(&event); - events.push(new_event) -} - fn handle_rw_event(event: FdEventData, out_events: &mut Vec) { let size = match event.descriptor { Descriptor::OsHandle(os_handle) => { @@ -366,7 +349,6 @@ pub(crate) fn poll_oneoff( match state { PollState::Ready => handle_rw_event(event, events), PollState::NotReady => {} // not immediately available, so just ignore - PollState::Closed => handle_hangup_event(event, events), // TODO check if actually a POLLHUP on Linux PollState::TimedOut => handle_timeout_event(timeout.unwrap().0, events), PollState::Error(ref e) => { error!("FIXME return real error");