mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
iosource/Manager: Reap dry sources while computing timeout
Avoids looping over the sources vector twice and should result in the same behavior.
This commit is contained in:
parent
b3118d2a48
commit
739a8ac509
1 changed files with 14 additions and 15 deletions
|
@ -126,20 +126,6 @@ void Manager::ReapSource(Source* src) {
|
|||
void Manager::FindReadySources(ReadySources* ready) {
|
||||
ready->clear();
|
||||
|
||||
// Remove sources which have gone dry. For simplicity, we only
|
||||
// remove at most one each time.
|
||||
for ( SourceList::iterator i = sources.begin(); i != sources.end(); ++i )
|
||||
if ( ! (*i)->src->IsOpen() ) {
|
||||
ReapSource(*i);
|
||||
sources.erase(i);
|
||||
break;
|
||||
}
|
||||
|
||||
// If there aren't any sources and exit_only_after_terminate is false, just
|
||||
// return an empty set of sources. We want the main loop to end.
|
||||
if ( Size() == 0 && (! BifConst::exit_only_after_terminate || run_state::terminating) )
|
||||
return;
|
||||
|
||||
double timeout = -1;
|
||||
IOSource* timeout_src = nullptr;
|
||||
bool time_to_poll = false;
|
||||
|
@ -151,7 +137,8 @@ void Manager::FindReadySources(ReadySources* ready) {
|
|||
}
|
||||
|
||||
// Find the source with the next timeout value.
|
||||
for ( auto src : sources ) {
|
||||
for ( auto i = sources.begin(); i != sources.end(); /* noop */ ) {
|
||||
auto* src = *i;
|
||||
auto iosource = src->src;
|
||||
if ( iosource->IsOpen() ) {
|
||||
double next = iosource->GetNextTimeout();
|
||||
|
@ -179,7 +166,19 @@ void Manager::FindReadySources(ReadySources* ready) {
|
|||
ready->push_back({pkt_src, -1, 0});
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else {
|
||||
ReapSource(src);
|
||||
i = sources.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
// If there aren't any sources and exit_only_after_terminate is false, just
|
||||
// return an empty set of sources. We want the main loop to end.
|
||||
if ( Size() == 0 && (! BifConst::exit_only_after_terminate || run_state::terminating) ) {
|
||||
ready->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
DBG_LOG(DBG_MAINLOOP, "timeout: %f ready size: %zu time_to_poll: %d\n", timeout, ready->size(), time_to_poll);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue