#include <string.h>
-#include "util.h"
+#include "timeval.h"
#include "cache.h"
#include "log.h"
usec = ((AvahiUsec) e->record->ttl) * 10000;
/* 2% jitter */
- usec = (AvahiUsec) g_random_double_range(usec*percent, usec*(percent+2));
+ usec = (AvahiUsec) g_random_double_range((gdouble) (usec*percent), (gdouble) (usec*(percent+2)));
/* g_message("next expiry: %lli (%s)", usec / 1000000, txt = avahi_record_to_string(e->record)); */
/* g_free(txt); */
g_assert(e);
e->state = AVAHI_CACHE_FINAL;
- g_get_current_time(&e->expiry);
+ gettimeofday(&e->expiry, NULL);
avahi_timeval_add(&e->expiry, 1000000); /* 1s */
update_time_event(c, e);
}
} else {
AvahiCacheEntry *e = NULL, *first;
- GTimeVal now;
+ struct timeval now;
- g_get_current_time(&now);
+ gettimeofday(&now, NULL);
/* This is an update request */
/* g_free(txt); */
}
+struct dump_data {
+ AvahiDumpCallback callback;
+ gpointer userdata;
+};
+
static void dump_callback(gpointer key, gpointer data, gpointer userdata) {
AvahiCacheEntry *e = data;
AvahiKey *k = key;
+ struct dump_data *dump_data = userdata;
g_assert(k);
g_assert(e);
+ g_assert(data);
for (; e; e = e->by_key_next) {
gchar *t = avahi_record_to_string(e->record);
- fprintf((FILE*) userdata, "%s\n", t);
+ dump_data->callback(t, dump_data->userdata);
g_free(t);
}
}
-void avahi_cache_dump(AvahiCache *c, FILE *f) {
+void avahi_cache_dump(AvahiCache *c, AvahiDumpCallback callback, gpointer userdata) {
+ struct dump_data data;
+
g_assert(c);
- g_assert(f);
+ g_assert(callback);
+
+ callback(";;; CACHE DUMP FOLLOWS ;;;", userdata);
+
+ data.callback = callback;
+ data.userdata = userdata;
- fprintf(f, ";;; CACHE DUMP FOLLOWS ;;;\n");
- g_hash_table_foreach(c->hash_table, dump_callback, f);
+ g_hash_table_foreach(c->hash_table, dump_callback, &data);
}
gboolean avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e) {
- GTimeVal now;
+ struct timeval now;
AvahiUsec age;
g_assert(c);
g_assert(e);
- g_get_current_time(&now);
+ gettimeofday(&now, NULL);
age = avahi_timeval_diff(&now, &e->timestamp)/1000000;