"select" (was "Re. Shared libraries linker error")

Guy Harris auspex!guy at uunet.uu.net
Fri Mar 24 07:49:46 AEST 1989


>In my experience, this assertion that using fd_sets will solve you
>problems in the case of binary (cf source) compatability is incorrect.

In my original posting, I described "improper" usage of "select" as:

	pass(ing) in pointers to "int"s rather than "fd_set"s, but pass(ing)
	the result of "getdtablesize()" as the first argument under the
	assumption that it will always return a number less than or equal
	to the number of bits in an "int"

and also said:

	...it (is) a bad idea to use "getdtablesize" - or, at least, to
	use it without cutting its value off at 32 - because the system
	might be changed to support more than (# of bits per "int") file
	descriptors...

which was not all meant to "assert that using fd_sets will solve your
problems in the case of binary compatibility".  It was meant to assert
that *not using 'getdtablesize()'*, but using, say, 32, would solve your
problems.  I should have made it clearer in the first paragraph that the
fix to the problem mentioned therein was not simply to change the first
part by passing in pointers to "fd_set"s.

"properly" doesn't just mean "use 'fd_set's"; it means "don't pass the
result of 'getdtablesize()' as the first argument unless you mean it" -
i.e., don't pass the result of 'getdtablesize()' unless you're actually
using file descriptor 'getdtablesize() - 1'.  The proper way to use
"select" - both for reasons of correctness *and* performance (see my
second posting) - is to pass one greater than the highest file descriptor
number you use as the first argument.  Thus, most programs will probably
pass a relatively small number - <= 32 - to "select" as the first
argument. 



More information about the Comp.sys.sun mailing list