Allow arbitrary when statement timeout expressions

BIT-1284 #close
This commit is contained in:
Jon Siwek 2014-10-31 10:35:02 -05:00
parent 285f93b689
commit 2a181a88c5
4 changed files with 24 additions and 6 deletions

View file

@ -1,4 +1,9 @@
2.3-267 | 2014-10-31 10:35:02 -0500
* BIT-1284: Allow arbitrary when statement timeout expressions
(Jon Siwek)
2.3-266 | 2014-10-31 09:21:28 -0500
* BIT-1166: Add configure options to fine tune local state dirs used

View file

@ -1 +1 @@
2.3-266
2.3-267

View file

@ -131,18 +131,19 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts,
arg_frame->SetDelayed();
}
Val* timeout = arg_timeout ? arg_timeout->ExprVal() : 0;
Val* timeout_val = arg_timeout ? arg_timeout->Eval(arg_frame) : 0;
// Make sure we don't get deleted if somebody calls a method like
// Timeout() while evaluating the trigger.
Ref(this);
if ( ! Eval() && timeout )
if ( ! Eval() && timeout_val )
{
timer = new TriggerTimer(timeout->AsInterval(), this);
timer = new TriggerTimer(timeout_val->AsInterval(), this);
timer_mgr->Add(timer);
}
Unref(timeout_val);
Unref(this);
}

View file

@ -8,13 +8,25 @@
event bro_init()
{
local h1: addr = 127.0.0.1;
local h: addr = 127.0.0.1;
when ( local h1name = lookup_addr(h1) )
when ( local hname = lookup_addr(h) )
{
print "lookup successful";
terminate();
}
timeout 10sec
{
print "timeout (1)";
}
local to = 5sec;
# Just checking that timeouts can use arbitrary expressions...
when ( local hname2 = lookup_addr(h) ) {}
timeout to {}
when ( local hname3 = lookup_addr(h) ) {}
timeout to + 2sec {}
print "done";
}