Why FD_SET/FD_ZERO for select() inside of loop?

When select returns, it has updated the sets to show which file descriptors have become ready for read/write/exception. All other flags have been cleared.

It's important that you re-enable the file descriptors that were cleared prior to starting another select, otherwise, you will no longer be waiting on those file descriptors.

As for re-clearing, it can be a good habit to get into, since if you need to change the set of file descriptors (such as adding a newly opened socket to the read set), you'll want to clear it and rebuilt it every time, so that it's correct as the state of the program changes.


Is it just because select modifies the contents of the set?

Yes, after select returns, only ready descriptors are left within the sets.