mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
f3fcaf776c
commit
5f1a85803a
2 changed files with 11 additions and 1 deletions
|
@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue