Date: Mon, 14 May 2007 17:05:51 +0200 From: Erik Trulsson <ertr1013@student.uu.se> To: MQ <antinvidia@gmail.com> Cc: freebsd-arch@freebsd.org Subject: Re: A problem with the select(2) interface Message-ID: <20070514150550.GA73252@owl.midgard.homeip.net> In-Reply-To: <be0088ce0705140729m4c24f2cbr21f6f050aac75c89@mail.gmail.com> References: <be0088ce0705140729m4c24f2cbr21f6f050aac75c89@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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. -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070514150550.GA73252>