Fix poll_oneoff behavior when fd_events are empty
This commit is contained in:
@@ -116,9 +116,27 @@ pub(crate) fn poll_oneoff(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use crate::fdentry::Descriptor;
|
use crate::fdentry::Descriptor;
|
||||||
use std::fs::Metadata;
|
use std::fs::Metadata;
|
||||||
if fd_events.is_empty() && timeout.is_none() {
|
use std::thread;
|
||||||
|
|
||||||
|
let timeout_duration = timeout
|
||||||
|
.map(|t| t.delay.try_into().map(Duration::from_nanos))
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
|
// With no events to listen, poll_oneoff just becomes a sleep.
|
||||||
|
if fd_events.is_empty() {
|
||||||
|
match timeout_duration {
|
||||||
|
Some(t) => {
|
||||||
|
thread::sleep(t);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
// The thread is not guanteed to remain parked forever, so we need to loop
|
||||||
|
loop {
|
||||||
|
thread::park();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Currently WASI file support is only (a) regular files (b) directories (c) symlinks on Windows,
|
// Currently WASI file support is only (a) regular files (b) directories (c) symlinks on Windows,
|
||||||
// which are always ready to write on Unix.
|
// which are always ready to write on Unix.
|
||||||
@@ -197,9 +215,6 @@ pub(crate) fn poll_oneoff(
|
|||||||
// a major issue.
|
// a major issue.
|
||||||
let poll_interval = Duration::from_millis(10);
|
let poll_interval = Duration::from_millis(10);
|
||||||
let poll_start = Instant::now();
|
let poll_start = Instant::now();
|
||||||
let timeout_duration = timeout
|
|
||||||
.map(|t| t.delay.try_into().map(Duration::from_nanos))
|
|
||||||
.transpose()?;
|
|
||||||
|
|
||||||
let timeout_occurred: Option<ClockEventData> = loop {
|
let timeout_occurred: Option<ClockEventData> = loop {
|
||||||
// Even though we assume that stdin is not ready, it's better to check it
|
// Even though we assume that stdin is not ready, it's better to check it
|
||||||
@@ -212,7 +227,7 @@ pub(crate) fn poll_oneoff(
|
|||||||
break timeout;
|
break timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::thread::sleep(poll_interval);
|
thread::sleep(poll_interval);
|
||||||
};
|
};
|
||||||
|
|
||||||
match timeout_occurred {
|
match timeout_occurred {
|
||||||
|
|||||||
Reference in New Issue
Block a user