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.
This commit is contained in:
Arne Welzel 2023-03-17 18:01:35 +01:00
parent f3fcaf776c
commit 5f1a85803a
2 changed files with 11 additions and 1 deletions

View file

@ -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<int>(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});
}
}

View file

@ -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=<uninitialized>, inner_vlan=<uninitialized>, 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=<uninitialized>, tcp=[sport=443/tcp, dport=49655/tcp, seq=2319610143, ack=3289393380, hl=32, dl=0, reserved=0, flags=18, win=8190], udp=<uninitialized>, icmp=<uninitialized>]
XXXXXXXXXX.XXXXXX event_queue_flush_point
XXXXXXXXXX.XXXXXX event_queue_flush_point
XXXXXXXXXX.XXXXXX event_queue_flush_point
XXXXXXXXXX.XXXXXX new_packet