mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
EventMgr: Do not cache current event attributes
Avoid proliferation of various members on EventMgr by storing the pointer of the current event instead. This subtly changes the behavior of some builtin functions as they would have returned the prior event's data when executed outside of event draining (e.g. C++ level hook invocations), but I think that's actually for the better.
This commit is contained in:
parent
bef923ebeb
commit
7dadbb0c1d
4 changed files with 30 additions and 39 deletions
26
src/Event.h
26
src/Event.h
|
@ -52,7 +52,6 @@ protected:
|
|||
|
||||
class EventMgr final : public Obj, public iosource::IOSource {
|
||||
public:
|
||||
EventMgr();
|
||||
~EventMgr() override;
|
||||
|
||||
/**
|
||||
|
@ -84,21 +83,23 @@ public:
|
|||
void Dispatch(Event* event, bool no_remote = false);
|
||||
|
||||
void Drain();
|
||||
bool IsDraining() const { return draining; }
|
||||
bool IsDraining() const { return current != nullptr; }
|
||||
|
||||
bool HasEvents() const { return head != nullptr; }
|
||||
|
||||
// Returns the source ID of last raised event.
|
||||
util::detail::SourceID CurrentSource() const { return current_src; }
|
||||
// Returns the source ID of the current event.
|
||||
util::detail::SourceID CurrentSource() const { return current ? current->Source() : util::detail::SOURCE_LOCAL; }
|
||||
|
||||
// Returns the ID of the analyzer which raised the last event, or 0 if
|
||||
// Returns the ID of the analyzer which raised the current event, or 0 if
|
||||
// non-analyzer event.
|
||||
analyzer::ID CurrentAnalyzer() const { return current_aid; }
|
||||
analyzer::ID CurrentAnalyzer() const { return current ? current->Analyzer() : 0; }
|
||||
|
||||
// Returns the timestamp of the last raised event. The timestamp reflects the network time
|
||||
// Returns the timestamp of the current event. The timestamp reflects the network time
|
||||
// the event was intended to be executed. For scheduled events, this is the time the event
|
||||
// was scheduled to. For any other event, this is the time when the event was created.
|
||||
double CurrentEventTime() const { return current_ts; }
|
||||
//
|
||||
// If no event is being processed, returns 0.0.
|
||||
double CurrentEventTime() const { return current ? current->Time() : 0.0; }
|
||||
|
||||
int Size() const { return num_events_queued - num_events_dispatched; }
|
||||
|
||||
|
@ -118,12 +119,9 @@ public:
|
|||
protected:
|
||||
void QueueEvent(Event* event);
|
||||
|
||||
Event* head;
|
||||
Event* tail;
|
||||
util::detail::SourceID current_src;
|
||||
analyzer::ID current_aid;
|
||||
double current_ts;
|
||||
bool draining;
|
||||
Event* current = nullptr;
|
||||
Event* head = nullptr;
|
||||
Event* tail = nullptr;
|
||||
};
|
||||
|
||||
extern EventMgr event_mgr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue