Code:
#include <time.h>
time_t startT = time(NULL);
bool gotData = false;
do
{
//wait for sender to send data
//send ack if needed
if( the data was recieved)
gotData = true;
}while( (!gotData) && (time(NULL) - startT ) < 10000 ); //this will wait 10 secs, but exit the loop if the data was already recieved
if( ! gotData )
{
//send request;
}
else
{
//you got the data!!!
}
time_t time( time_t * t ) returns the time in milliseconds.
1000 milliseconds = 1 second
You can pass it a pointer to a time_t data type and it will store the current time there, as well as returning it