A problem with the select(2) interface
Erik Trulsson
ertr1013 at student.uu.se
Mon May 14 15:21:10 UTC 2007
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 at student.uu.se
More information about the freebsd-arch
mailing list