Event handlers are nearly identical in both syntax and semantics to functions, with the two differences being that event handlers have no return type since they never return a value, and you cannot call an event handler. You declare an event handler using:
event ( argumentSo, or example,)
local eh: event(attack_source: addr, severity: count)declares the local variable eh to have a type corresponding to an event handler that takes two arguments, attack_source of type addr, and severity of type count.
To declare an event handler along with its body, the syntax is:
event handler ( argument) { statement
}
As with functions, you can assign event handlers to variables of the same type. Instead of calling event handlers like functions, though, instead they are invoked. This can happen in one of three ways:
event password_exposed(c, user, password);queues an inovocation of the event handler password_exposed with the arguments c, user, and password. Note that password_exposed must have been previously declared as an event handler with a compatible set of arguments.
Or, if we had a local variable eh as defined above, we could execute:
event eh(src, how_severe);if src is of type addr and how_severe of type count.
schedule 5 secs { password_exposed(c, user, password) };would cause password_exposed to be invoked 5 seconds in the future.