diff options
author | Lennart Poettering <lennart@poettering.net> | 2005-11-16 01:15:46 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2005-11-16 01:15:46 +0000 |
commit | a3d45b39608418e261f34b3b3286b80e4878d25c (patch) | |
tree | 0743b13f2386f4e108dc8e6d17fc0d3cf18e4791 /avahi-core/cache.c | |
parent | 6ed9be1191edab688976f5ea7ddf1e382ef6f1d1 (diff) |
* when calculating a random jitter time for time events, use the same jitter in
every 10s timespans. This should increase the probability that multiple
responses can be merged into a single packet, and thus decreases network
traffic.
* add _workstation._tcp services in RUNNING state, not earlier
* an important bugfix which fixes the entry group state automatons
* remove obsolete debug messages
* minor other cleanups
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@980 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core/cache.c')
-rw-r--r-- | avahi-core/cache.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/avahi-core/cache.c b/avahi-core/cache.c index c26b6bb..3a8f849 100644 --- a/avahi-core/cache.c +++ b/avahi-core/cache.c @@ -25,6 +25,7 @@ #include <string.h> #include <stdlib.h> +#include <time.h> #include <avahi-common/timeval.h> #include <avahi-common/malloc.h> @@ -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); |