From owner-freebsd-arch@FreeBSD.ORG Mon May 14 15:21:10 2007 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 84EAC16A405 for ; Mon, 14 May 2007 15:21:10 +0000 (UTC) (envelope-from erikt@midgard.homeip.net) Received: from ch-smtp02.sth.basefarm.net (ch-smtp02.sth.basefarm.net [80.76.149.213]) by mx1.freebsd.org (Postfix) with ESMTP id 12B0413C458 for ; Mon, 14 May 2007 15:21:09 +0000 (UTC) (envelope-from erikt@midgard.homeip.net) Received: from c83-253-10-135.bredband.comhem.se ([83.253.10.135]:49402 helo=falcon.midgard.homeip.net) by ch-smtp02.sth.basefarm.net with smtp (Exim 4.66) (envelope-from ) id 1Hnc7V-0002yH-7K for freebsd-arch@freebsd.org; Mon, 14 May 2007 17:05:53 +0200 Received: (qmail 6746 invoked from network); 14 May 2007 17:05:51 +0200 Received: from owl.midgard.homeip.net (10.1.5.7) by falcon.midgard.homeip.net with SMTP; 14 May 2007 17:05:51 +0200 Received: (qmail 73311 invoked by uid 1001); 14 May 2007 17:05:51 +0200 Date: Mon, 14 May 2007 17:05:51 +0200 From: Erik Trulsson To: MQ Message-ID: <20070514150550.GA73252@owl.midgard.homeip.net> Mail-Followup-To: MQ , freebsd-arch@freebsd.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.14 (2007-02-12) X-ACL-Warn: Too high rate of unknown addresses received from you X-Scan-Result: No virus found in message 1Hnc7V-0002yH-7K. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1Hnc7V-0002yH-7K 9ef597d30aacaf2c5a3e4b4b8c197282 Cc: freebsd-arch@freebsd.org Subject: Re: A problem with the select(2) interface X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 May 2007 15:21:10 -0000 On Mon, May 14, 2007 at 10:29:15PM +0800, MQ wrote: > Hi, > I'm writing a network application these days, for compatibility, I choose > the select(2) interface to do event polling. When using it, I'm curious > about the fact that the type of the final parameter is `struct timeval *'. I > skimmed through the codes in /sys/kern/sys_generic.c, there is nothing > written to this address. So, I think if we can use `const struct timeval *' > instead? This type can inform the users explicitly that we do NOT modify the > timeval struct. But I'm not sure if this modification will conflict with the > POSIX standard. Will you please tell me your considerations? Any suggestions > will be appreciated. > Thanks. Some other implementations *do* write to that adress. >From the select(2) manpage on a Linux system: On Linux, select() modifies timeout to reflect the amount of time not slept; most other imple- mentations do not do this. (POSIX.1-2001 permits either behaviour.) This causes problems both when Linux code which reads timeout is ported to other operating systems, and when code is ported to Linux that reuses a struct timeval for multiple select()s in a loop without reini- tializing it. Consider timeout to be undefined after select() returns. The FreeBSD select(2) manpage says: BUGS Version 2 of the Single UNIX Specification (`SUSv2'') allows systems to modify the original timeout in place. Thus, it is unwise to assume that the timeout value will be unmodified by the select() system call. -- Erik Trulsson ertr1013@student.uu.se