Subject: Re: FD_SETSIZE in sys/types.h
To: Michael Graff <explorer@flame.org>
From: Pete Bentley <pete@demon.net>
List: current-users
Date: 05/31/1996 12:03:03
At Thu, 30 May 1996 15:11:59 EDT, Michael Graff writes:
>> Is the accepted method to
>> 	#define FD_SETSIZE 1024
>> before including sys/types.h?  Will things break if that size were
>> increased to something larger (2048 even?) and will I have to
>> recompile a kernel to allow me to USE those?

That is the only way to do it.  However, as you spotted, unless you
recompile the kernel with a value of FD_SETSIZE which matches the
one you are using, things will break --- if the kernel value of
FD_SETSIZE is greater than the user-space it will only break if you
pass in a silly value for nfds to select(), if the kernel value is
less, then it will fail to test file descriptors numbered greater than
FD_SETSIZE. 

It is possible to implement select in the kernel so that it is
independant of FD_SETSIZE and just uses the value of nfds passed in,
something I have been meaning to do for a while.  OpenBSD has such a
change, but it looks like their version incurs a kernel malloc() and
free() for every select which uses more file descriptors than the
default FD_SETSIZE ... rather inefficient in an application that might
be multiplexing very large numbers of descriptors in a loop.

Pete.