ecore_avahi: fix timeout to be relative from now.

This commit is contained in:
Cedric Bail 2014-02-27 20:07:22 -03:00
parent cbf6f94c80
commit b955ea0b9e
1 changed files with 13 additions and 4 deletions

View File

@ -44,7 +44,7 @@ _ecore_avahi_events2ecore(AvahiWatchEvent events)
{
return (events & AVAHI_WATCH_IN ? ECORE_FD_READ : 0) |
(events & AVAHI_WATCH_OUT ? ECORE_FD_WRITE : 0) |
(events & AVAHI_WATCH_ERR ? ECORE_FD_ERROR : 0);
ECORE_FD_ERROR;
}
static Eina_Bool
@ -119,8 +119,17 @@ _ecore_avahi_watch_get_events(AvahiWatch *w)
static double
_ecore_avahi_timeval2double(const struct timeval *tv)
{
struct timeval now;
double tm;
if (!tv) return 3600;
return tv->tv_sec + (double) tv->tv_usec / 1000000;
gettimeofday(&now, NULL);
tm = tv->tv_sec - now.tv_sec + (double) (tv->tv_usec - now.tv_usec) / 1000000;
if (tm < 0) tm = 0.001;
return tm;
}
static Eina_Bool
@ -144,8 +153,8 @@ _ecore_avahi_timeout_new(const AvahiPoll *api, const struct timeval *tv,
ea = api->userdata;
timeout = calloc(1, sizeof (Ecore_Avahi_Timeout));
if (!timeout) return NULL;
timeout->timer = ecore_timer_add(_ecore_avahi_timeval2double(tv), _ecore_avahi_timeout_cb, timeout);
timeout->timer = ecore_timer_add(_ecore_avahi_timeval2double(tv),
_ecore_avahi_timeout_cb, timeout);
if (!tv) ecore_timer_freeze(timeout->timer);
timeout->callback = callback;
timeout->callback_data = userdata;