Date: Thu, 13 Mar 2003 01:57:16 -0500 From: David Cuthbert <dacut@kanga.org> To: hackers@freebsd.org Subject: Re: first parameter to select Message-ID: <3E702BCC.3030208@kanga.org>
next in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E702BCC.3030208>