Process timer
When implementing a protocol, an event for a future time is often scheduled. Whenever yousend a packet on the network, you must assume that it, or the response to it, might go astray.After a suitable time has elapsed, you may want to attempt a retry or alert the user.Most modern operating systems have a built-in provision for scheduling such events, but Iam very keen to keep the code Operating System (OS) independent and to be able to run it onthe bare metal of small embedded systems. To this end, my software includes a minimal eventscheduler of its own, which requires a minimum of OS support and can be adapted to use thespecific features of your favorite OS.
The simplest scheduling algorithm is to have timeout.
putpacket(...); /* Packet Tx */timeout(&txtimer, 0); /* Start timer */
while (1){ /* Check for packet Rx */
if (getpacket(...)) { /* Handle response packet */ } /* Check for timeout on response */
else if (timeout(&txtimer, 2)) { /* Handle error condition */ }
/* Check for other events */
else if ... }











