[jdev] Why are we doing math on socket handles?

Greg Hewgill greg at hewgill.com
Tue Apr 5 09:17:35 CDT 2005

On Tue, Apr 05, 2005 at 10:08:09AM -0400, Bresler, Jonathan wrote:
> If Windows ignores the max_fd parameter then it must act pessimally
> and check the entire array for all conditions.  It?s a choice of the
> writers of the OS.

In the Win32 select() function, the fd_set parameters are implemented
differently. Typically on unix, the set is implemented as a bit vector
with bit <n> set to 1 to indicate handle <n> is a member of the set.
Each byte contains flags for 8 handles. The maxfd parameter tells the
socket() function how far to look in each array for set bits.

On Win32, the set is implemented as an array of handle values. Rather
than assuming the numeric handle values are all going to be less than
some maximum value, the fd_set is a sequence of 32-bit handle values.
The fd_set itself holds information about how big the set of handles
is, so the maxfd parameter to select() is unneeded.

Each implementation is a tradeoff, one is not intrinsically better than
the other.

Greg Hewgill

More information about the JDev mailing list