From root@do-labs.spb.ru  Sat Oct 13 11:55:55 2001
Return-Path: <root@do-labs.spb.ru>
Received: from milliways.chance.ru (milliways.chance.ru [195.190.107.35])
	by hub.freebsd.org (Postfix) with ESMTP id 9A95837B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 13 Oct 2001 11:55:53 -0700 (PDT)
Received: from do-labs.spb.ru (ppp-4.chance.ru [195.190.107.7])
	by milliways.chance.ru (8.9.0/8.9.0) with SMTP id WAA04128
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 13 Oct 2001 22:55:45 +0400 (MSD)
Received: (qmail 7153 invoked by uid 0); 13 Oct 2001 22:56:59 -0000
Message-Id: <20011013225659.7152.qmail@do-labs.spb.ru>
Date: 13 Oct 2001 22:56:59 -0000
From: root@do-labs.spb.ru
Reply-To: root@do-labs.spb.ru
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: select with zero timeout returns 0 even when data pending
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         31255
>Category:       kern
>Synopsis:       select with zero timeout returns 0 even when data pending
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 13 12:00:06 PDT 2001
>Closed-Date:    Sun Dec 01 11:16:14 PST 2002
>Last-Modified:  Sun Dec 01 11:16:14 PST 2002
>Originator:     dozen@osw.com.ru
>Release:        FreeBSD 4.3-RELEASE-p20 i386
>Organization:
>Environment:
System: FreeBSD eix.do-labs.spb.ru 4.3-RELEASE-p20 FreeBSD 4.3-RELEASE-p20 #1: Fri Oct 12 22:18:27 GMT 2001 root@eix.do-labs.spb.ru:/usr/src/sys/compile/EIX i386


	
>Description:
        struct timeval tv = { 0,0 };
        rc = select(...,&tv);

        This code will always return zero even if data is pending
        one any descriptor or any descriptor is ready to write.
        This is because check for timed out performed before 
        asking kernel about descriptor state.

	Single Unix Spec do not states exactly that zero timeout shall
        lead to immediate return with correct descriptor number as result,
        but it looks like it is supposed to be as such.

>How-To-Repeat:
	
>Fix:
        The problem code is in /usr/src/sys/kern/sys_generic.c

>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: <root@do-labs.spb.ru>
Cc: <FreeBSD-gnats-submit@FreeBSD.ORG>
Subject: Re: kern/31255: select with zero timeout returns 0 even when data
 pending
Date: Sun, 14 Oct 2001 12:09:41 +1000 (EST)

 On 13 Oct 2001 root@do-labs.spb.ru wrote:
 
 > >Description:
 >         struct timeval tv = { 0,0 };
 >         rc = select(...,&tv);
 >
 >         This code will always return zero even if data is pending
 >         one any descriptor or any descriptor is ready to write.
 >         This is because check for timed out performed before
 >         asking kernel about descriptor state.
 
 I can't see this.  The descriptors are checked before the timeout.  The
 timeout is just copyin()'ed and (bogusly) validated early, so select()
 may return an error for certain problems with the timeout even when there
 is a ready descriptor so there is no need to use the timeout.
 
 > 	Single Unix Spec do not states exactly that zero timeout shall
 >         lead to immediate return with correct descriptor number as result,
 >         but it looks like it is supposed to be as such.
 
 POSIX.1-200x-draft7 seems to be exact enough.  It says that if none of
 the descriptors are ready, then select() shall block until one becomes
 ready or the timeout expires, etc.  It doesn't say anything about using
 the timeout if a descriptor is ready.
 
 Bruce
 
State-Changed-From-To: open->closed 
State-Changed-By: iedowse 
State-Changed-When: Sun Dec 1 11:13:01 PST 2002 
State-Changed-Why:  

Using select with a zero timeout to poll for ready descriptors works 
fine for me, and many things depend on it working. Without example 
code that demonstrates it not working, I can only assume it was a 
bug in your code that calls select. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=31255 
>Unformatted:
