X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fcache.c;h=4ba88b5f62ff17b7ce88afe9a160221075a72a77;hb=a2fd5b8ed02be912fcb71cdec1c9233692d6c615;hp=c26b6bb9d81225e592faf0b370b7cd877eb21a79;hpb=da75d1898a45c106a994cd87f8da5b6bcb2b6450;p=catta diff --git a/avahi-core/cache.c b/avahi-core/cache.c index c26b6bb..4ba88b5 100644 --- a/avahi-core/cache.c +++ b/avahi-core/cache.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -86,6 +87,8 @@ AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *iface) { AVAHI_LLIST_HEAD_INIT(AvahiCacheEntry, c->entries); c->n_entries = 0; + + c->last_rand_timestamp = 0; return c; } @@ -235,6 +238,7 @@ static void update_time_event(AvahiCache *c, AvahiCacheEntry *e) { static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, unsigned percent) { AvahiUsec usec, left, right; + time_t now; assert(c); assert(e); @@ -245,7 +249,14 @@ static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, unsigned percent) { left = usec * percent; right = usec * (percent+2); /* 2% jitter */ - usec = left + (AvahiUsec) ((double) (right-left) * rand() / (RAND_MAX+1.0)); + now = time(NULL); + + if (now >= c->last_rand_timestamp + 10) { + c->last_rand = rand(); + c->last_rand_timestamp = now; + } + + usec = left + (AvahiUsec) ((double) (right-left) * c->last_rand / (RAND_MAX+1.0)); e->expiry = e->timestamp; avahi_timeval_add(&e->expiry, usec); @@ -469,7 +480,7 @@ void avahi_cache_start_poof(AvahiCache *c, AvahiKey *key, const AvahiAddress *a) assert(c); assert(key); - avahi_cache_walk(c, key, start_poof_callback, a); + avahi_cache_walk(c, key, start_poof_callback, (void*) a); } void avahi_cache_stop_poof(AvahiCache *c, AvahiRecord *record, const AvahiAddress *a) {