How to write a C program to Check While packet(s) hasn't been acked in C programming Language ?
Solution For C Program :
void *chitcpd_run_timeout_thread_t(void *threadargs)
{
retrans_queue_item_t *retrans = (retrans_queue_item_t *) threadargs;
chilog(TRACE, "Spawned new timeout thread.");
/* check while packet(s) hasn't been acked */
while (!retrans->acked)
{
int rc = pthread_cond_timedwait(
retrans->ack_condvar,
retrans->mutex,
retrans->timeout
);
if (rc == ETIMEDOUT)
{
chilog(TRACE, "THREAD GENERATING TIMEOUT");
retrans->timed_out = TRUE;
chitcpd_timeout(retrans->si, retrans->entry);
pthread_exit(NULL);
}
}
chilog(INFO, "Packet in retransmission queue ACK'ed. Exiting thread.");
pthread_exit(NULL);
}