I have this while loop:
while (notdone) {
//Set the timers
waitd.tv_sec = 5;
waitd.tv_usec = 0;
FD_ZERO(&tempreadfds);
FD_ZERO(&tempwritefds);
FD_ZERO(&readfds); /* initialize the read fd set */
FD_ZERO(&writefds); /* initialize the write fd set */
FD_SET(parentfd, &readfds); /* add listener socket fd */
FD_SET(0, &readfds); /* add stdin fd (0) */
tempreadfds = readfds; //make a copy
tempwritefds = writefds; //make a copy
rv = select(fdmax+1, &tempreadfds, &tempwritefds, (fd_set*) 0, &waitd);
if (rv < 0) {
error("ERROR in select");
} else if(rv == 0) {
printf("Timeout occurred! No data after 5 seconds\n");
}
printf("Select called\n");
fflush(stdout);
}
I was assuming that "Select called" should be printed every 5 seconds but it gets printed only once. Can someone tell me what mistake I am doing?