cnet v4.0.4 | |
home topology files command‑line options the core API FAQ download and install |
cnet's Timers
A total of 10 software timer queues
are supported to provide a call-back mechanism for user code.
For example,
when a data frame is transmitted a timer is typically created which will
expire sometime after that frame's acknowledgement is expected.
Timers are referenced via unique values termed timers
of datatype
When a timer expires,
the event handler for the corresponding event
(one of
Timers may be cancelled with There are an unlimited number of timersIt is important to understand that an unlimited number of timers may be started on each queue - there are not just 10 timers. For example, the following section of code:
void timeouts(CnetEvent ev, CnetTimerID timer, CnetData data)
{
int i = (int)data;
printf("tick number %d\n", i);
}
void reboot_node(CnetEvent ev, CnetTimerID timer, CnetData data)
{
CNET_set_handler(EV_TIMER3, timeouts, 0);
for(int sec=1 ; sec<=10 ; ++sec)
CNET_start_timer(EV_TIMER3, (CnetTime)sec*1000000, (CnetData)sec);
}
will produce output identical to that from:
void timeouts(CnetEvent ev, CnetTimerID timer, CnetData data)
{
int i = (int)data;
printf("tick number %d\n", i);
if(i < 10)
CNET_start_timer(EV_TIMER3, (CnetTime)1000000, (CnetData)i+1);
}
void reboot_node(CnetEvent ev, CnetTimerID timer, CnetData data)
{
CNET_set_handler(EV_TIMER3, timeouts, 0);
CNET_start_timer(EV_TIMER3, (CnetTime)1000000, (CnetData)1);
}
In the first example, there are initially 10 timers running simultaneously.
When each expires, the (same) handler for
In the second example,
there is only ever 1 timer running at one time,
and when it expires a new timer is started in the |