Listing 1: Implementation of timeout periods
while (YES) { /* loop forever - return on expected reply or a timeout */
/* read a single character from the communication port */
if ((bytes = read (fpPort, &c, 1)) == -1) {
printf ("port read failure - %s\n", strerror (errno));
exit (1);
}
if (bytes == 0) { /* timeout */
if (++tries == seconds)
return (TIMEOUT);
}
else if (bytes > 0) { /* successfully read a character */
...
/* End of File */
|