Re: checks against FD_SETSIZE in _PR_MD_PR_POLL() function (w32poll.c)

Wan-Teh Chang <[email protected]> Mon, 17 Nov 2008 14:54:21 -0800
Newsgroups gmane.comp.mozilla.devel.nspr
Message-ID <[email protected]>
On Mon, Nov 17, 2008 at 1:40 PM, Aleksey Sanin <[email protected]> wrote:
> Hi All!
>
> There is a check for FD_SETSIZE in _PR_MD_PR_POLL()
> function (w32poll.c):
>
> if ((nrd > FD_SETSIZE) || (nwt > FD_SETSIZE) || (nex > FD_SETSIZE)) {
>    PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
>    return -1;
> }
>
> and I am not sure what is the purpose of this check. It seems
> like the WinSock select() function has no restriction on the
> number of sockets passed in. Could you please clarify this?

The check against FD_SETSIZE ensures that we can manipulate
'fd_set' safely.  The "size" of fd_set is fixed at compile time by
the macro FD_SETSIZE.  On Unix, fd_set is a bitmask, so
FD_SETSIZE specifies the maximum numeric value of fd that
you can put in a fd_set.  On Windows, fd_set is an array of
SOCKETs, so FD_SETSIZE is the maximum number of fd's
that a fd_set can hold (i.e., the size of that array).

The difference between the two is subtle.  Suppose FD_SETSIZE
is 1024.  On Unix, this means you can't put even just one fd
with value 1030 in the fd_set.  On Windows, you can put up
to 1024 fd's, regardless of their numeric values, in the fd_set.

Wan-Teh