Skip to content

Commit 7f8a61f

Browse files
committed
fix(driver,poll): wait first
1 parent de30815 commit 7f8a61f

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

  • compio-driver/src/sys/driver/poll

compio-driver/src/sys/driver/poll/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,26 @@ impl Driver {
438438
self.renew(fd, renew_event)
439439
}
440440

441-
pub fn poll(&mut self, timeout: Option<Duration>) -> io::Result<()> {
441+
pub fn poll(&mut self, mut timeout: Option<Duration>) -> io::Result<()> {
442442
instrument!(compio_log::Level::TRACE, "poll", ?timeout);
443-
if self.poll_completed() {
444-
return Ok(());
443+
let has_completed = !self.completed_rx.is_empty();
444+
if has_completed {
445+
timeout = Some(Duration::ZERO);
445446
}
447+
// We need to poll the poller first to make sure it handles the internal notify
448+
// event (if any).
446449
self.events.clear();
447450
self.notify.poll.wait(&mut self.events, timeout)?;
448-
if self.events.is_empty() && timeout.is_some() {
449-
// No events received, but returned. We need to reset the awake flag to allow
450-
// next notify to work.
451-
self.notify.set_awake(false);
452-
return Err(io::Error::from_raw_os_error(libc::ETIMEDOUT));
451+
self.notify.set_awake(false);
452+
if self.events.is_empty() {
453+
if self.poll_completed() {
454+
return Ok(());
455+
}
456+
if timeout.is_some() {
457+
return Err(io::Error::from_raw_os_error(libc::ETIMEDOUT));
458+
}
459+
} else if has_completed {
460+
self.poll_completed();
453461
}
454462
self.with_events(|this, events| {
455463
for event in events.iter() {

0 commit comments

Comments
 (0)