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 CnetTimerID.

When a timer expires, the event handler for the corresponding event (one of EV_TIMER0..EV_TIMER9) is invoked with the event and unique timer as parameters.

Timers may be cancelled with CNET_stop_timer to prevent them expiring (for example, if the acknowledgement frame arrives before the timer expires). Timers are automatically cancelled as a result of their handler being invoked.


There are an unlimited number of timers

It 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 EV_TIMER3 will be called.

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 EV_TIMER3 event handler.


cnet v4.0.4 - [email protected]