Sean Hamilton wrote:

> What is the first parameter to select(2) for? Microsoft's select ignores it,
> and it does not appear to have any valid use since it only allows
> constraints on values which are assigned by the system.
>
> Purely historic?



Ah, you've been reading the Winsock documentation.


fd_set is usually a fixed-size bitmask of filedescriptors (this implementation isn't guaranteed, but I haven't seen another). The number of bits corresponds to the maximum number of files a process can have open (according to your header files; tweaks to your kernel and process limits can dictate otherwise).

select() needs to know how many of those bits (descriptors) to scan. Passing in FD_SETSIZE will tell it to scan all of the bits. But most processes only have a few handles open, so the majority of the scanning goes to waste. Instead (except on Microsoft's Winsock, which always assumes FD_SETSIZE regardless of what you pass in), you can tell it to stop at bit/descriptor N, where N is the highest numbered descriptor in all of the fd_set bitmasks passed to select().

To be honest, I've never passed anything but FD_SETSIZE for this parameter. When I'm writing a performance critical server, I use poll() instead. It's faster and I don't have to reinitialize the fd_set bitmasks on each iteration. It's technically less portable, but I've never had an issue across Solaris, HP-UX, Linux, or FreeBSD.



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to