Avoid issuing syscalls if we're requested to return immediately
This commit is contained in:
@@ -188,10 +188,9 @@ pub(crate) fn poll_oneoff(
|
|||||||
let new_event = make_read_event(&event, size);
|
let new_event = make_read_event(&event, size);
|
||||||
events.push(new_event)
|
events.push(new_event)
|
||||||
}
|
}
|
||||||
}
|
} else if !stdin_events.is_empty() {
|
||||||
|
|
||||||
// There are some stdin poll requests and there's no data available immediately
|
// There are some stdin poll requests and there's no data available immediately
|
||||||
if !stdin_events.is_empty() {
|
|
||||||
// We are busy-polling the stdin with delay, unfortunately.
|
// We are busy-polling the stdin with delay, unfortunately.
|
||||||
//
|
//
|
||||||
// We'd like to do the following:
|
// We'd like to do the following:
|
||||||
@@ -213,6 +212,15 @@ pub(crate) fn poll_oneoff(
|
|||||||
//
|
//
|
||||||
// However, polling stdin is a relatively infrequent use case, so this hopefully won't be
|
// However, polling stdin is a relatively infrequent use case, so this hopefully won't be
|
||||||
// a major issue.
|
// a major issue.
|
||||||
|
let timeout_duration = timeout
|
||||||
|
.map(|t| t.delay.try_into().map(Duration::from_nanos))
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
|
// avoid issuing more syscalls if we're requested to return immediately
|
||||||
|
if timeout_duration == Some(Duration::from_nanos(0)) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let poll_interval = Duration::from_millis(10);
|
let poll_interval = Duration::from_millis(10);
|
||||||
let poll_start = Instant::now();
|
let poll_start = Instant::now();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user