LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   question about select sys call (https://www.linuxquestions.org/questions/programming-9/question-about-select-sys-call-378292/)

xatzipol 10-30-2005 06:45 AM

question about select sys call
 
hello people

lets say that i want to use the select sys call as in the example

FD(fd1,&rdf);
FD(fd2,&rdf);
FD(fd3,&rdf);
FD(fd4,&rdf);

while(1){ //let's say that this is the server main loop

select(10, &rdf , NULL , NULL , NULL) ; //waiting select for reading from rdf set

if(FD_ISSET(fd1,&rdf)){ //let's say that fd1 has data for reading

.... //code here
}
?
} //end of loop

after the select returns (so we have something to read from... let's say fd1 as in example)
do i have to re-add the fd's (fd1,fd2,fd3,fd4) in the rdf set before the main loop ends(in the question mark) or there is no problem so i don't add anything in the above piece of code?

thanks

naf 10-30-2005 09:22 AM

First off, dont forget to zero out the fd set:
FD_ZERO( &rdf );

Because you are a server, you might want to consider checking the return value of select (it can error).

To answer your question: yes, you would have to reconstruct the fd sets because the select operation will alter the sets pointed to. The zeroing can be done once, but you may want to re-SET the fds you want and CLR the ones you don't on subsequent calls.


All times are GMT -5. The time now is 07:36 AM.