kern/45291: kevent(2) ignores timeout if nevents == 0

John Polstra jdp at polstra.com
Sun Oct 19 10:38:45 PDT 2003


On 19-Oct-2003 Boris Nikolaus wrote:
> On Thu, Oct 16, 2003 at 10:09:58AM -0700, John-Mark Gurney wrote:
>> events to wait for.  In fact, after reading select's manpage, this
>> misfeature isn't documented, and select really should return EINVAL
>> if nfds is 0, and -1 is an invalid fd (which is the last fd that
>> select is suppose to check)..
> 
> Select's manpage says, it checks all file descriptors from 0 to
> nfds - 1.  The set of whole numbers which are >= 0 and <= -1 is empty,
> so select has to check no descriptors and waits for the timeout.  This
> is exactly what select does, so this behaviour is implicitely
> documented.
> 
> Changing select's behaviour as you suggest would break many software
> as this behavious is often used, both in main loops (which have to
> observe a set of file descriptors and timers and do not want to
> handle the case "only timers left" in a special way) and explicitely
> for sleeping (before microsleep/nanosleep have been invented, there
> was no function for sleeping with resolution below seconds, so the
> common way for sleeping in these cases was to call select with
> nfds == 0).

Boris is right about this, John-Mark.  If you think otherwise then
you really need to go read the code in a few real-world event loops.
They absolutely rely on this behavior of select.  If anybody changed
it they'd have a whole lot of broken programs on their hands.  You may
view it as a case of lazy programmers using the wrong system call for
sleeping, but in fact it is just the proper and most sensible behavior
for select to have at this boundary condition.

John


More information about the freebsd-bugs mailing list