question about select() and range of for loop to read sockets

Posted by Fantastic Fourier on Stack Overflow See other posts from Stack Overflow or by Fantastic Fourier
Published on 2010-03-24T01:41:07Z Indexed on 2010/03/24 1:43 UTC
Read the original article Hit count: 287

Filed under:
|
|

Just a quick question about using select().

I'm using select() to read from multiple sockets. When I looked up examples on how to use select(), a lot of tutorials showed going through for loops and checking for FD_ISSET. The problem I have with those tutorials is that the for loop starts from i = 0. and checks if the bit has been set for the file descriptor i using FD_ISSET. Couldn't the for loop start from say your minfd (just like how you would keep track of maxfd)?? Or am I missing something??

Following link is an example of such for loop (look at the fourth example that he gives) http://www.developerweb.net/forum/showthread.php?t=2933

If that was the only example out there that used such for loop, I might understand it was a mistake or bad coding but I've seen several examples of such for loop of uselessly going through literally thousands of sockets and I'm convinced I'm missing something. Any comments or inputs are appreciated.

© Stack Overflow or respective owner

Related posts about c

    Related posts about select