mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
PktSrc: Add HasBeenIdleFor() method
This method will be used by the main loop to determine if an interface has become idle. Initially this will be used to determine when it is acceptable to update network_time to the current time (wallclock).
This commit is contained in:
parent
a9f8627dd9
commit
eefa0150b9
2 changed files with 42 additions and 0 deletions
|
@ -139,6 +139,16 @@ void PktSrc::Done()
|
|||
Close();
|
||||
}
|
||||
|
||||
bool PktSrc::HasBeenIdleFor(double interval) const
|
||||
{
|
||||
if ( have_packet || had_packet )
|
||||
return false;
|
||||
|
||||
// Take the hit of a current_time() call now.
|
||||
double now = zeek::util::current_time(true);
|
||||
return idle_at_wallclock < now - interval;
|
||||
};
|
||||
|
||||
void PktSrc::Process()
|
||||
{
|
||||
if ( ! IsOpen() )
|
||||
|
@ -191,6 +201,18 @@ bool PktSrc::ExtractNextPacketInternal()
|
|||
}
|
||||
else
|
||||
{
|
||||
// Update the idle_at timestamp the first time we've failed
|
||||
// to extract a packet. This assumes ExtractNextPacket() is
|
||||
// called regularly which is true for non-selectable PktSrc
|
||||
// instances, but even for selectable ones with an FD the
|
||||
// main-loop will call Process() on the interface regularly
|
||||
// and detect it as idle.
|
||||
if ( had_packet )
|
||||
{
|
||||
DBG_LOG(DBG_PKTIO, "source %s is idle now", props.path.c_str());
|
||||
idle_at_wallclock = zeek::util::current_time(true);
|
||||
}
|
||||
|
||||
had_packet = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue