From 83fa43badc59a54641b0c2319a8a8e4d0f9d9b85 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 16 Jul 2005 23:48:35 +0000 Subject: [PATCH] Fix cache managament git-svn-id: file:///home/lennart/svn/public/avahi/trunk@168 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/browse.c | 9 +++++---- avahi-core/cache.c | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/avahi-core/browse.c b/avahi-core/browse.c index d9da80c..2d14c90 100644 --- a/avahi-core/browse.c +++ b/avahi-core/browse.c @@ -25,6 +25,7 @@ #include "browse.h" #include "util.h" +#include "log.h" struct AvahiRecordBrowser { gboolean dead; @@ -48,7 +49,7 @@ struct AvahiRecordBrowser { static void elapse(AvahiTimeEvent *e, void *userdata) { AvahiRecordBrowser *s = userdata; GTimeVal tv; -/* gchar *t; */ +/* gchar *t; */ g_assert(s); @@ -58,9 +59,9 @@ static void elapse(AvahiTimeEvent *e, void *userdata) { if (s->sec_delay >= 60*60) /* 1h */ s->sec_delay = 60*60; - -/* avahi_log_debug("%i. Continuous querying for %s", s->n_query, t = avahi_key_to_string(s->key)); */ -/* g_free(t); */ + +/* avahi_log_debug("Continuous querying for %s (%i)", t = avahi_key_to_string(s->key), s->sec_delay); */ +/* g_free(t); */ avahi_elapse_time(&tv, s->sec_delay*1000, 0); avahi_time_event_queue_update(s->server->time_event_queue, s->time_event, &tv); diff --git a/avahi-core/cache.c b/avahi-core/cache.c index 865950f..52304a8 100644 --- a/avahi-core/cache.c +++ b/avahi-core/cache.c @@ -27,6 +27,7 @@ #include "util.h" #include "cache.h" +#include "log.h" #define AVAHI_MAX_CACHE_ENTRIES 200 @@ -151,13 +152,16 @@ static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, guint percent); static void elapse_func(AvahiTimeEvent *t, void *userdata) { AvahiCacheEntry *e = userdata; +/* gchar *txt; */ g_assert(t); g_assert(e); +/* txt = avahi_record_to_string(e->record); */ + if (e->state == AVAHI_CACHE_FINAL) { remove_entry(e->cache, e); -/* avahi_log_debug("Removing entry from cache due to expiration"); */ +/* avahi_log_debug("Removing entry from cache due to expiration (%s)", txt); */ } else { guint percent = 0; @@ -189,13 +193,15 @@ static void elapse_func(AvahiTimeEvent *t, void *userdata) { /* Request a cache update, if we are subscribed to this entry */ if (avahi_is_subscribed(e->cache->server, e->cache->interface, e->record->key)) { -/* avahi_log_debug("Requesting cache entry update at %i%%.", percent); */ +/* avahi_log_debug("Requesting cache entry update at %i%% for %s.", percent, txt); */ avahi_interface_post_query(e->cache->interface, e->record->key, TRUE); } /* Check again later */ next_expiry(e->cache, e, percent); } + +/* g_free(txt); */ } static void update_time_event(AvahiCache *c, AvahiCacheEntry *e) { @@ -209,20 +215,25 @@ static void update_time_event(AvahiCache *c, AvahiCacheEntry *e) { } static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, guint percent) { - gulong usec; - g_assert(c); g_assert(e); g_assert(percent > 0 && percent <= 100); + gdouble usec; +/* gchar *txt; */ - e->expiry = e->timestamp; - usec = e->record->ttl * 10000; + usec = (gdouble) e->record->ttl * 10000; /* 2% jitter */ - usec = g_random_int_range(usec*percent, usec*(percent+2)); + usec = g_random_double_range(usec*percent, usec*(percent+2)); +/* g_message("next expiry: %g (%s)", usec / 1000000.0, txt = avahi_record_to_string(e->record)); */ +/* g_free(txt); */ + + e->expiry = e->timestamp; + g_time_val_add(&e->expiry, (glong) usec); + +/* g_message("wake up in +%lu seconds", e->expiry.tv_sec - e->timestamp.tv_sec); */ - g_time_val_add(&e->expiry, usec); update_time_event(c, e); } -- 2.39.5