Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: select/poll bug?

On Saturday 02 August 2008 17:11:17 David Brownlee wrote:
> On Sat, 2 Aug 2008, Roy Marples wrote:
> > On Sat, 2008-08-02 at 11:25 -0400, Christos Zoulas wrote:
> >> On Aug 2,  4:12pm, (Roy Marples) wrote:
> >> -- Subject: Re: select/poll bug?
> >>
> >> | On Sat, 2008-08-02 at 14:26 +0000, Christos Zoulas wrote:
> >> | > On NetBSD you should use pollts(2) I think.
> >> |
> >> | pselect is more portable I would guess, but platforms like OpenBSD
> >> | lack either. I could trivially add a pselect wrapper for systems that
> >> | lack it. But would pselect avoid the need to artifically reduce my
> >> | timers on ALL platforms?
> >> |
> >> | I'll test it :)
> >>
> >> The select family of system calls is generally inferior to poll because:
> >>
> >> 1. Expensive because you need do operations on bitmasks [ffs/shifts].
> >> 2. Expensive because you need to reset the masks before each call.
> >> 3. Non portable behavior for >= 256 fd's. All systems need source
> >>    recompilation; some older systems need kernel recompilation.
> >> 4. Non-portable behavior with respect to ERESTART.
> >> 5. Non-portable behavior when running out of resources. The only
> >>    way to fix this is using non-blocking-io which is a bit of a pain.
> >> 6. Non-portable behavior with respect to "struct timeval *timeout".
> >>    This is non-const, and it was originally intended to return
> >>    the time left. Most implementations did not change "timeout", but
> >>    one or two did, so it is always good to re-initialize "timeout".
> >> 7. Can only report 3 types of events, read/write/except.
> >
> > Only 1 & 2 would apply here I think. We only monitor 4 fd's which are
> > all non blocking, we don't care about modified timeval and I only care
> > if something is to be read from the fd.
> >
> > Linux has ppoll, NetBSD has pollts - no other platform has any
> > equivalents I can find.
>       At least ppoll() and pollts() appear to take the same
>       arguments, so handling both of them is not too much of
>       a PITA... plus maybe a compat shim down to poll() for
>       everything else?

OK, testing shows at select, pselect and pollts all suffer the same flaw, so 
it now boils down to which one is best for dhcpcd.

select is 100% portable in terms of how it is used by dhcpcd.
pselect should be as it's mandated by POSIX, but OpenBSD lacks it. However a 
simple wrapper is trivial.
ppoll/pollts are platform specific functions.
poll itself is NOT suitable as the timeout cannot handle a DHCP lease of 
uint32_t seconds on 32-bit platforms.

We only listen on 4 fd's, we only care if we have data read from them, they 
are all non-blocking, we need to be able to handle up to uint32_t seconds for 
a timeout. So at this point I'll keep the select code unless someone can give 
a good technical reason otherwise :)

I do actually have a question though - internally do select/poll and friends 
all use a timespec? I ask as I current convert the timespec from 
clock_gettime to a timeval, and if a timespec is used internally then it's an 
argument for using at least pselect.

Lastly, should I file a PR asking for the non exact timeout informating being 
added to the select/poll man pages?



Home | Main Index | Thread Index | Old Index