A problem with the select(2) interface

Dag-Erling Smørgrav des at des.no
Mon May 14 15:25:41 UTC 2007


MQ <antinvidia at gmail.com> writes:
> 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.

According to POSIX, the struct timeval may be updated to reflect the
amount of time left if select() returns early (so you can call select()
again with the same struct timeval and hit your original deadline).  In
reality, there is so much old code around that depends on it *not* being
updated that this has never been implemented.

This is often mentioned as an example of why blindly implementing a
standard is not a good idea.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-arch mailing list