When using select(), I understand that the process is:
- Fill up a fd_set structure with the file descriptors you want to know when data comes in on.
- Fill up a fd_set structure with the file descriptors you want to know when you can write on.
- Call select() and block until something happens.
- Once select() returns, call ISSET() on all your file descriptors to see if something happened with them, and service them accordingly.
- Repeat.
What I don't understand, however, is what exactly it means for a file descriptor to be "set". In this documentation, it says that it means the file descriptor is part of the specified fd_set. But if ISSET() checks if something happened with the file descriptor, why you "setting" each file descriptor at the beginning of each iteration, before select() is even called? Aren't they only supposed to be "set" when something changes? Can they be "unset" at some point before select() returns?
selectchanges the value of thefd_setthat is passed in (via pointer). So the value of thefd_setafter the call can be different to before the call. For example, you may set 10 fds to monitor for read data but afterselectreturns only 1 fd may be set as only 1 is ready with data.. - kaylum