When a timer expires, the event handler for the corresponding event (one of EV_TIMER1..EV_TIMER10) 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.
void timeouts(CnetEvent ev, CnetTimer timer, CnetData data)
{
int i = (int)data;
(void)printf("tick number %d\n", i);
}
void reboot_node(CnetEvent ev, CnetTimer timer, CnetData data)
{
(void)CNET_set_handler(EV_TIMER3, timeouts, 0);
for(i=1 ; i<=10 ; ++i)
(void)CNET_start_timer(EV_TIMER3, i*1000L, (CnetData)i);
}
will produce output identical to that from:
void timeouts(CnetEvent ev, CnetTimer timer, CnetData data)
{
int i = (int)data;
printf("tick number %d\n", i);
if(i < 10)
(void)CNET_start_timer(EV_TIMER3, 1000L, (CnetData)i+1);
}
void reboot_node(CnetEvent ev, CnetTimer timer, CnetData data)
{
(void)CNET_set_handler(EV_TIMER3, timeouts, 0);
(void)CNET_start_timer(EV_TIMER3, 1000L, (CnetData)1);
}
Requests that a new timer be created which will expire in the indicated number of milliseconds. One of the 10 timer queues may be requested by passing one of the event types EV_TIMER1..EV_TIMER10. A unique timer is returned to distinguish this newly created timer from all others. This timer should later be used in subsequent calls to CNET_stop_timer(). If a new timer cannot be created, NULLTIMER will be returned.
Possible errors: ER_BADARG.
Requests that the indicated timer be cancelled (before it has expired).
Possible errors: ER_BADTIMER.
Allows the CnetData value for the indicated CnetTimer value to be recovered. The timer is not cancelled.
Possible errors: ER_BADTIMER, ER_BADARG.
| cnet was written and is maintained by Chris McDonald (chris@cs.uwa.edu.au) | ![]() |