From 5f1a85803a5e651d2073b6bd3cb0fb038a38de22 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 17 Mar 2023 18:01:35 +0100 Subject: [PATCH] iomanager/Poll: Add zero-timeout timeout_src also when there's other events ready This would generally happen the next loop iteration around anyway, but seems nice to ensure a zero timeout source will be processed at the same time as sources with ready FDs. --- src/iosource/Manager.cc | 11 +++++++++++ .../really-all-events.log | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/iosource/Manager.cc b/src/iosource/Manager.cc index da2f790cb8..537965674a 100644 --- a/src/iosource/Manager.cc +++ b/src/iosource/Manager.cc @@ -213,6 +213,8 @@ void Manager::Poll(ReadySources* ready, double timeout, IOSource* timeout_src) } else if ( ret == 0 ) { + // If a timeout_src was provided and nothing else was ready, we timed out + // according to the given source's timeout and can add it as ready. if ( timeout_src ) ready->push_back({timeout_src, -1, 0}); } @@ -220,6 +222,7 @@ void Manager::Poll(ReadySources* ready, double timeout, IOSource* timeout_src) { // kevent returns the number of events that are ready, so we only need to loop // over that many of them. + bool timeout_src_added = false; for ( int i = 0; i < ret; i++ ) { if ( events[i].filter == EVFILT_READ ) @@ -236,7 +239,15 @@ void Manager::Poll(ReadySources* ready, double timeout, IOSource* timeout_src) ready->push_back({it->second, static_cast(events[i].ident), IOSource::ProcessFlags::WRITE}); } + + // If we added a source that is the same as the passed timeout_src, take + // note as to avoid adding it twice. + timeout_src_added |= ready->size() > 0 ? ready->back().src == timeout_src : false; } + + // A timeout_src with a zero timeout can be considered ready. + if ( timeout_src && timeout == 0.0 && ! timeout_src_added ) + ready->push_back({timeout_src, -1, 0}); } } diff --git a/testing/btest/Baseline/scripts.policy.misc.dump-events/really-all-events.log b/testing/btest/Baseline/scripts.policy.misc.dump-events/really-all-events.log index 65b11800d7..eeab6929ec 100644 --- a/testing/btest/Baseline/scripts.policy.misc.dump-events/really-all-events.log +++ b/testing/btest/Baseline/scripts.policy.misc.dump-events/really-all-events.log @@ -8591,7 +8591,6 @@ XXXXXXXXXX.XXXXXX tcp_options XXXXXXXXXX.XXXXXX raw_packet [0] p: raw_pkt_hdr = [l2=[encap=LINK_ETHERNET, len=66, cap_len=66, src=cc:b2:55:f4:62:92, dst=58:b0:35:86:54:8d, vlan=, inner_vlan=, eth_type=2048, proto=L3_IPV4], ip=[hl=20, tos=0, len=52, id=50798, ttl=242, p=6, src=17.167.150.73, dst=192.168.133.100], ip6=, tcp=[sport=443/tcp, dport=49655/tcp, seq=2319610143, ack=3289393380, hl=32, dl=0, reserved=0, flags=18, win=8190], udp=, icmp=] -XXXXXXXXXX.XXXXXX event_queue_flush_point XXXXXXXXXX.XXXXXX event_queue_flush_point XXXXXXXXXX.XXXXXX event_queue_flush_point XXXXXXXXXX.XXXXXX new_packet