From 28d51a4496e9a8ca6d2caec46861480cb8f18e92 Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Tue, 12 Dec 2023 03:42:53 +0000 Subject: [PATCH] Only push back entry if ready_events is not empty --- .../libs/aster-std/src/fs/epoll/epoll_file.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/libs/aster-std/src/fs/epoll/epoll_file.rs b/services/libs/aster-std/src/fs/epoll/epoll_file.rs index 6206d1bc2..528276678 100644 --- a/services/libs/aster-std/src/fs/epoll/epoll_file.rs +++ b/services/libs/aster-std/src/fs/epoll/epoll_file.rs @@ -243,11 +243,21 @@ impl EpollFile { // If this entry's file is ready, save it in the output array. // EPOLLHUP and EPOLLERR should always be reported. let ready_events = entry.poll() & (ep_event.events | IoEvents::HUP | IoEvents::ERR); - if !ready_events.is_empty() { - ep_events.push(EpollEvent::new(ready_events, ep_event.user_data)); - count_events += 1; + // If there are no events, the entry should be removed from the ready list. + if ready_events.is_empty() { + entry.reset_ready(); + // For EPOLLONESHOT flag, this entry should also be removed from the interest list + if ep_flags.intersects(EpollFlags::ONE_SHOT) { + self.del_interest(entry.fd()) + .expect("this entry should be in the interest list"); + } + continue; } + // Records the events from the ready list + ep_events.push(EpollEvent::new(ready_events, ep_event.user_data)); + count_events += 1; + // If the epoll entry is neither edge-triggered or one-shot, then we should // keep the entry in the ready list. if !ep_flags.intersects(EpollFlags::ONE_SHOT | EpollFlags::EDGE_TRIGGER) {