Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 May 2007 06:53:32 +0000
From:      MQ <antinvidia@gmail.com>
To:        MQ <antinvidia@gmail.com>, freebsd-arch@freebsd.org
Subject:   Re: A problem with the select(2) interface
Message-ID:  <be0088ce0705142353s2a0af9banad1609ea5bfe18c4@mail.gmail.com>
In-Reply-To: <20070514150550.GA73252@owl.midgard.homeip.net>
References:  <be0088ce0705140729m4c24f2cbr21f6f050aac75c89@mail.gmail.com> <20070514150550.GA73252@owl.midgard.homeip.net>

next in thread | previous in thread | raw e-mail | index | archive | help
2007/5/14, Erik Trulsson <ertr1013@student.uu.se>:
>
> 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
>

I've considered that some OSes may write to that address before I initially
posted to this mailing list. The key point here is that FreeBSD does NOT do
this, and I want to know the committers' opinions about adding a `const'
qualifier to the type.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?be0088ce0705142353s2a0af9banad1609ea5bfe18c4>