diff -ur dhcdbd-2.0.bak/src/dbus_service.c dhcdbd-2.0/src/dbus_service.c --- dhcdbd-2.0.bak/src/dbus_service.c 2007-05-14 20:02:41.000000000 +0100 +++ dhcdbd-2.0/src/dbus_service.c 2007-05-14 20:05:23.000000000 +0100 @@ -976,6 +976,51 @@ twalk(cs->timeouts, process_timeout); } +static float next_timeout; + +static void find_timeout (const void *p, const VISIT which, const int level) { + DBusConnectionState *cs; + const void *const *tpp = p; + DBusConnectionTimeout *to; + struct timeval tv; + float now, then, interval, timeout; + + gettimeofday(&tv, 0L); + + if ((tpp != 0L) && (*tpp != 0L) && ((which == postorder) || (which == leaf))) { + to = (DBusConnectionTimeout *) * tpp; + cs = to->cs; + + if (!dbus_timeout_get_enabled(to->to)) + return; + + cs = dbus_timeout_get_data(to->to); + then = ((float) to->tv.tv_sec) + (((float) to->tv.tv_usec) / 1000000.0); + + if (then != 0.0) { + interval = ((float) dbus_timeout_get_interval(to->to)) / 1000.0; + now = ((float) tv.tv_sec) + (((float) tv.tv_usec) / 1000000.0); + + timeout = then + interval - now; + if (timeout < 0) + timeout = 0; + if (next_timeout < 0 || timeout < next_timeout) + next_timeout = timeout; + } + } +} + +static struct timeval *find_next_timeout (DBusConnectionState * cs, struct timeval *tv) { + next_timeout = 1; + twalk(cs->timeouts, find_timeout); + printf ("next timeout %f\n", next_timeout); + if (next_timeout == -1) + return NULL; + tv->tv_sec = next_timeout; + tv->tv_usec = (next_timeout - tv->tv_sec) * 1000000; + return tv; +} + static void set_watch_fds(DBusWatch * watch, DBusConnectionState * cs) { uint8_t flags = dbus_watch_get_flags(watch); int fd = dbus_watch_get_fd(watch); @@ -1147,10 +1192,8 @@ cs->s_w_fds = cs->w_fds; cs->s_e_fds = cs->e_fds; - timeout.tv_sec = 0; - timeout.tv_usec = 200000; - - if ((n_fds = select(cs->n, &(cs->s_r_fds), &(cs->s_w_fds), &(cs->s_e_fds), &timeout)) < 0) { + if ((n_fds = select(cs->n, &(cs->s_r_fds), &(cs->s_w_fds), + &(cs->s_e_fds), find_next_timeout (cs, &timeout))) < 0) { if (errno != EINTR) { if (cs->eh != 0L) (*(cs->eh)) ("select failed: %d : %s", errno, strerror(errno)); Only in dhcdbd-2.0/src: dbus_service.c.orig