Fix writing timeout events. Check that we only return one timeout event.
This commit is contained in:
@@ -65,11 +65,17 @@ unsafe fn test_stdin_read() {
|
||||
r#type: wasi::EVENTTYPE_CLOCK,
|
||||
u: wasi::SubscriptionU { clock },
|
||||
},
|
||||
// Make sure that timeout is returned only once even if there are multiple read events
|
||||
wasi::Subscription {
|
||||
userdata: 1,
|
||||
r#type: wasi::EVENTTYPE_FD_READ,
|
||||
u: wasi::SubscriptionU { fd_readwrite },
|
||||
},
|
||||
wasi::Subscription {
|
||||
userdata: 42,
|
||||
r#type: wasi::EVENTTYPE_FD_READ,
|
||||
u: wasi::SubscriptionU { fd_readwrite },
|
||||
},
|
||||
];
|
||||
let out = poll_oneoff_impl(&r#in, 1);
|
||||
let event = &out[0];
|
||||
|
||||
@@ -95,7 +95,7 @@ fn make_rw_event(event: &FdEventData, nbytes: Result<u64>) -> wasi::__wasi_event
|
||||
}
|
||||
}
|
||||
|
||||
fn make_timeout_event(event: &FdEventData, timeout: &ClockEventData) -> wasi::__wasi_event_t {
|
||||
fn make_timeout_event(timeout: &ClockEventData) -> wasi::__wasi_event_t {
|
||||
wasi::__wasi_event_t {
|
||||
userdata: timeout.userdata,
|
||||
r#type: wasi::__WASI_EVENTTYPE_CLOCK,
|
||||
@@ -125,7 +125,12 @@ pub(crate) fn poll_oneoff(
|
||||
// With no events to listen, poll_oneoff just becomes a sleep.
|
||||
if fd_events.is_empty() {
|
||||
match timeout_duration {
|
||||
Some(t) => thread::sleep(t),
|
||||
Some(t) => {
|
||||
thread::sleep(t);
|
||||
let timeout_event = timeout.expect("timeout should be Some");
|
||||
let new_event = make_timeout_event(&timeout_event);
|
||||
events.push(new_event);
|
||||
}
|
||||
// `poll` invoked with nfds = 0, timeout = -1 appears to be an infinite sleep
|
||||
// Even though the thread is not guanteed to remain parked forever, `poll(2)`
|
||||
// mentions that spurious readiness notifications may occur, so it's probably fine
|
||||
@@ -236,11 +241,9 @@ pub(crate) fn poll_oneoff(
|
||||
|
||||
match timeout_occurred {
|
||||
Some(timeout_info) => {
|
||||
for event in stdin_events {
|
||||
let new_event = make_timeout_event(&event, &timeout_info);
|
||||
let new_event = make_timeout_event(&timeout_info);
|
||||
events.push(new_event);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
// stdin became ready for reading
|
||||
for event in stdin_events {
|
||||
|
||||
Reference in New Issue
Block a user