Hi,
For those who are interested in using timers for retransmission, here is the stub code.
I am using 'setitimer' . Search on Internet for more information.
//timer structure
struct itimerval tTimer;
//timeout signal handler structure
struct sigaction sTimeout;
//Timeout handler function
void TimeoutHandler();
//Starting the timer
void StartTimer()
{
//Assiging the timeout handler (Signal handler for "SIGALRM")
memset (&sTimeout,0, sizeof (struct sigaction ));
sTimeout.sa_handler = &TimeoutHandler; // timeout handler function
sigaction (SIGALRM, &sTimeout, NULL);
//Setting the timer
tTimer.it_value.tv_sec = REQUIRED_TIME_IN_SEC;
tTimer.it_value.tv_usec = 0; //Required time in milliseconds
setitimer (ITIMER_REAL, &tTimer, NULL);
}
void TimeoutHandler()
{
// do something
}
//stopping the timer.
boolean StopTimer()
{
memset (&sTimeout,0, sizeof (sTimeout));
sTimeout.sa_handler =NULL;
tTimer.it_value.tv_sec = 0; tTimer.it_value.tv_usec = 0;
setitimer (ITIMER_REAL, &tTimer, NULL);
return TRUE;
}
Hope this helps.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment