[Xorp-users] select timeout question
Ben Greear
greearb at candelatech.com
Thu Sep 27 23:19:35 PDT 2007
Pavlin Radoslavov wrote:
> Ben Greear <greearb at candelatech.com> wrote:
>
>> If you pass a timeout of 0 to selector::wait_and_dispatch, it causes select to wait 'forever'.
>> Is that on purpose or a bug? If you want to wait for zero time in select, pass a time-val
>> with all zero values (not 0, which is actually treated as NULL).
>>
>> if (timeout == 0 || *timeout == TimeVal::MAXIMUM()) {
>> n = ::select(_maxfd + 1,
>> &testfds[SEL_RD_IDX],
>> &testfds[SEL_WR_IDX],
>> &testfds[SEL_EX_IDX],
>> 0);
>> } else {
>
> I believe it is on purpose.
> Part of the logic behind it is probably because select(2) with
> "timeout" argument of NULL also blocks forever.
> One extreme scenario that comes to mind is, say, if there are no
> timeout events scheduled. In that case you want to select() until a
> file descriptor is ready (for reading/writing/etc).
>
> Strictly speaking, the "timeout" argument doesn't need to be a
> pointer; instead, it could be pass-by-reference argument.
> In fact, the more I think, the more I believe it should be
> pass-by-reference. Then, if some code really wants to select(2)
> without timeout, the caller should use TimeVal::MAXIMUM() as an
> argument.
>
> And yes, TimeVal::ZERO() is used typically to schedule a timer that
> will expire immediately.
Bleh, I see. Timeout is a pointer. Would have been more
clear if the code was: timeout == NULL
Ben
>
> Thanks,
> Pavlin
>
>> --
>> Ben Greear <greearb at candelatech.com>
>> Candela Technologies Inc http://www.candelatech.com
>>
>> _______________________________________________
>> Xorp-users mailing list
>> Xorp-users at xorp.org
>> http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-users
--
Ben Greear <greearb at candelatech.com>
Candela Technologies Inc http://www.candelatech.com
More information about the Xorp-users
mailing list