[avahi] `avahi_simple_poll_iterate ()' with TIMEOUT > 0

Ludovic Courtès ludovic.courtes at laas.fr
Fri Mar 10 08:42:22 PST 2006


Hi,

ludovic.courtes at laas.fr (Ludovic Courtès) writes:

> Sure, but it actually never does anything, even with TIMEOUT == INT_MAX.

Thanks to Sébastien (on IRC), I solved this issue.  Basically, the key
point, as Sébastien noted earlier, is that `iterate' waits *at most*
TIMEOUT msecs.

As a matter of fact, the ten first iterations or so almost all return
"immediately", whatever timeout was passed, giving the impression that
it does nothing and does not care about TIMEOUT.

If one wants to loop for exactly TIMEOUT msecs, regardless of whether
events were processed or not, one has to call `iterate' within a loop:

  unsigned remaining = timeout;

  while (remaining)
    {
      unsigned long elapsed;
      struct timeval before, after;

      gettimeofday (&before, NULL);
      err = chop_store_browser_iterate (browser, timeout);
      gettimeofday (&after, NULL);


      elapsed = (after.tv_sec - before.tv_sec) * 1000;
      if (elapsed)
        elapsed += (1e3 - (before.tv_usec / 1000))
          + (after.tv_usec / 1000);
      else
        elapsed += (after.tv_usec - before.tv_usec) / 1000;

      remaining = (remaining > elapsed) ? (remaining - elapsed) : 0;
    }

Thanks,
Ludovic.


More information about the avahi mailing list