Having some trouble with select() call in C

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?

Hello,

Difficult to tell from the code you posted. A few questions:

  • What do you mean by "it gets printed only once". Do you mean that subsequent select() blocks?
  • what's the point with tempreadfs and tempwritefs? Why don't you use readfs/writefs directly?
  • where is fdmax set?

Could you perhaps post a minimalistic example that we can compile and that illustrates your problem?

Thanks,
Lo�c.