From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 31 15:45:13 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 68C5F106566B for ; Sun, 31 Jul 2011 15:45:13 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id 097B38FC1B for ; Sun, 31 Jul 2011 15:45:13 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id D778A1DD6DF; Sun, 31 Jul 2011 17:45:11 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id CC89B1742A; Sun, 31 Jul 2011 17:45:11 +0200 (CEST) Date: Sun, 31 Jul 2011 17:45:11 +0200 From: Jilles Tjoelker To: "Christoph P.U. Kukulies" Message-ID: <20110731154511.GB66652@stack.nl> References: <4E356498.40001@kukulies.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4E356498.40001@kukulies.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org Subject: Re: invalid argument in select() when peer socket is in FD_SET X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jul 2011 15:45:13 -0000 On Sun, Jul 31, 2011 at 04:20:08PM +0200, Christoph P.U. Kukulies wrote: > I posted this on freebsd-questions also but maybe the expert density > isn't that high as here in "hackers". > Since I think it may be a design or implementation issue in FreeBSDs' > select(), I'm posting it here as well, > hoping to get an experts' answer. > I have written a small server to test TCP/IP roundtrip times of the > packets in a proprietary protocol and while > compiling and running this server on different platforms (Windows > 7/cygwin, UbuntuLinux, FreeBSD 8.0 Release), I found > that the server produces an error when the listening socket (on which > the accept() is performed) is also > member of the select() fd_set. > On the other platforms the program works without error, just under > FreeBSD I'm getting this "invalid argument" error. > Comments appreciated (despite comments about the error checking logic > [snip] > tv.tv_sec = 0; > tv.tv_usec = 5000000; /* 5 seconds */ > [snip] > n = select(nfds, &readfds, > (fd_set *) NULL, /* not interested in write */ > (fd_set *) NULL, /* ...or exceptions */ > &tv); /* timeout */ The number of microseconds in a struct timeval must be nonnegative and less than one million (likewise, the number of nanoseconds in a struct timespec must be nonnegative and less than 1000 million). FreeBSD checks this strictly in most functions. -- Jilles Tjoelker