X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fcache.c;h=0a39194c7ae45e91474af523b7779acb61498dd3;hb=38b45921cd1d33119f1c06979a57bcfe982e22da;hp=865950f65bb464240bf29f3db41c3b8d593f09d7;hpb=c0244c2448a5504581ae24e78b5859760b999b8e;p=catta diff --git a/avahi-core/cache.c b/avahi-core/cache.c index 865950f..0a39194 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,24 @@ 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); + AvahiUsec usec; +/* gchar *txt; */ - e->expiry = e->timestamp; - - usec = e->record->ttl * 10000; + usec = ((AvahiUsec) e->record->ttl) * 10000; /* 2% jitter */ - usec = g_random_int_range(usec*percent, usec*(percent+2)); + usec = (AvahiUsec) g_random_double_range(usec*percent, usec*(percent+2)); +/* g_message("next expiry: %lli (%s)", usec / 1000000, txt = avahi_record_to_string(e->record)); */ +/* g_free(txt); */ + + e->expiry = e->timestamp; + avahi_timeval_add(&e->expiry, 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); } @@ -232,7 +242,7 @@ static void expire_in_one_second(AvahiCache *c, AvahiCacheEntry *e) { e->state = AVAHI_CACHE_FINAL; g_get_current_time(&e->expiry); - g_time_val_add(&e->expiry, 1000000); /* 1s */ + avahi_timeval_add(&e->expiry, 1000000); /* 1s */ update_time_event(c, e); } @@ -242,8 +252,7 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean cache_flush, con g_assert(c); g_assert(r && r->ref >= 1); -/* avahi_log_debug("cache update: %s", (txt = avahi_record_to_string(r))); */ -/* g_free(txt); */ +/* txt = avahi_record_to_string(r); */ if (r->ttl == 0) { /* This is a goodbye request */ @@ -267,7 +276,7 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean cache_flush, con /* For unique entries drop all entries older than one second */ for (e = first; e; e = e->by_key_next) { - glong t; + AvahiUsec t; t = avahi_timeval_diff(&now, &e->timestamp); @@ -295,10 +304,12 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean cache_flush, con avahi_record_unref(e->record); e->record = avahi_record_ref(r); +/* avahi_log_debug("cache: updating %s", txt); */ + } else { /* No entry found, therefore we create a new one */ -/* avahi_log_debug("couldn't find matching cache entry"); */ +/* avahi_log_debug("cache: couldn't find matching cache entry for %s", txt); */ if (c->n_entries >= AVAHI_MAX_CACHE_ENTRIES) return; @@ -327,6 +338,8 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean cache_flush, con e->state = AVAHI_CACHE_VALID; e->cache_flush = cache_flush; } + +/* g_free(txt); */ } static void dump_callback(gpointer key, gpointer data, gpointer userdata) { @@ -353,7 +366,7 @@ void avahi_cache_dump(AvahiCache *c, FILE *f) { gboolean avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e) { GTimeVal now; - guint age; + AvahiUsec age; g_assert(c); g_assert(e); @@ -362,7 +375,7 @@ gboolean avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e) { age = avahi_timeval_diff(&now, &e->timestamp)/1000000; -/* avahi_log_debug("age: %u, ttl/2: %u", age, e->record->ttl); */ +/* avahi_log_debug("age: %lli, ttl/2: %u", age, e->record->ttl); */ return age >= e->record->ttl/2; }