@@ -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