]> git.meshlink.io Git - catta/blobdiff - avahi-core/response-sched.c
* Rename various data structures to prevent a namespace conflict with avahi-core
[catta] / avahi-core / response-sched.c
index 1e763e6366cb4beeae9455b60e21e7cad858e810..6027287dae19f68eaa93133c5af966dde337d681 100644 (file)
 #endif
 
 #include "response-sched.h"
-#include "util.h"
+#include "timeval.h"
 #include "log.h"
 
-#define AVAHI_RESPONSE_HISTORY_MSEC 700
+#define AVAHI_RESPONSE_HISTORY_MSEC 500
 #define AVAHI_RESPONSE_DEFER_MSEC 20
 #define AVAHI_RESPONSE_JITTER_MSEC 100
 #define AVAHI_RESPONSE_SUPPRESS_MSEC 700
@@ -45,7 +45,7 @@ struct AvahiResponseJob {
     AvahiTimeEvent *time_event;
     
     AvahiResponseJobState state;
-    GTimeVal delivery;
+    struct timeval delivery;
 
     AvahiRecord *record;
     gboolean flush_cache;
@@ -108,7 +108,7 @@ static void job_free(AvahiResponseScheduler *s, AvahiResponseJob *rj) {
 static void elapse_callback(AvahiTimeEvent *e, gpointer data);
 
 static void job_set_elapse_time(AvahiResponseScheduler *s, AvahiResponseJob *rj, guint msec, guint jitter) {
-    GTimeVal tv;
+    struct timeval tv;
 
     g_assert(s);
     g_assert(rj);
@@ -134,7 +134,7 @@ static void job_mark_done(AvahiResponseScheduler *s, AvahiResponseJob *rj) {
 
     job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0);
 
-    g_get_current_time(&rj->delivery);
+    gettimeofday(&rj->delivery, NULL);
 }
 
 AvahiResponseScheduler *avahi_response_scheduler_new(AvahiInterface *i) {
@@ -284,7 +284,9 @@ static AvahiResponseJob* find_history_job(AvahiResponseScheduler *s, AvahiRecord
         if (avahi_record_equal_no_ttl(rj->record, record)) {
             /* Check whether this entry is outdated */
 
-            if (avahi_age(&rj->delivery) > AVAHI_RESPONSE_HISTORY_MSEC*1000) {
+/*             avahi_log_debug("history age: %u", (unsigned) (avahi_age(&rj->delivery)/1000)); */
+            
+            if (avahi_age(&rj->delivery)/1000 > AVAHI_RESPONSE_HISTORY_MSEC) {
                 /* it is outdated, so let's remove it */
                 job_free(s, rj);
                 return NULL;
@@ -327,20 +329,25 @@ static AvahiResponseJob* find_suppressed_job(AvahiResponseScheduler *s, AvahiRec
 
 gboolean avahi_response_scheduler_post(AvahiResponseScheduler *s, AvahiRecord *record, gboolean flush_cache, const AvahiAddress *querier, gboolean immediately) {
     AvahiResponseJob *rj;
-    GTimeVal tv;
+    struct timeval tv;
+/*     gchar *t; */
     
     g_assert(s);
     g_assert(record);
 
     g_assert(!avahi_key_is_pattern(record->key));
 
+/*     t = avahi_record_to_string(record); */
+/*     avahi_log_debug("post %i %s", immediately, t); */
+/*     g_free(t); */
+
     /* Check whether this response is suppressed */
     if (querier &&
         (rj = find_suppressed_job(s, record, querier)) &&
         avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) &&
         rj->record->ttl >= record->ttl/2) {
 
-/*         avahi_log_debug("Response suppressed by known answer suppression."); */
+/*         avahi_log_debug("Response suppressed by known answer suppression.");  */
         return FALSE;
     }
 
@@ -350,7 +357,7 @@ gboolean avahi_response_scheduler_post(AvahiResponseScheduler *s, AvahiRecord *r
         if (avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) &&
             rj->record->ttl >= record->ttl/2 &&
             (rj->flush_cache || !flush_cache)) {
-/*             avahi_log_debug("Response suppressed by local duplicate suppression (history)"); */
+/*             avahi_log_debug("Response suppressed by local duplicate suppression (history)");  */
             return FALSE;
         }
 
@@ -361,7 +368,7 @@ gboolean avahi_response_scheduler_post(AvahiResponseScheduler *s, AvahiRecord *r
     avahi_elapse_time(&tv, immediately ? 0 : AVAHI_RESPONSE_DEFER_MSEC, immediately ? 0 : AVAHI_RESPONSE_JITTER_MSEC);
          
     if ((rj = find_scheduled_job(s, record))) {
-/*         avahi_log_debug("Response suppressed by local duplicate suppression (scheduled)"); */
+/*          avahi_log_debug("Response suppressed by local duplicate suppression (scheduled)"); */
 
         /* Update a little ... */
 
@@ -385,7 +392,7 @@ gboolean avahi_response_scheduler_post(AvahiResponseScheduler *s, AvahiRecord *r
 
         return TRUE;
     } else {
-/*         avahi_log_debug("Accepted new response job."); */
+/*         avahi_log_debug("Accepted new response job.");  */
 
         /* Create a new job and schedule it */
         rj = job_new(s, record, AVAHI_SCHEDULED);
@@ -433,7 +440,7 @@ void avahi_response_scheduler_incoming(AvahiResponseScheduler *s, AvahiRecord *r
     rj->flush_cache = flush_cache;
     rj->querier_valid = FALSE;
     
-    g_get_current_time(&rj->delivery);
+    gettimeofday(&rj->delivery, NULL);
     job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0);
 }
 
@@ -470,7 +477,7 @@ void avahi_response_scheduler_suppress(AvahiResponseScheduler *s, AvahiRecord *r
         rj->querier = *querier;
     }
 
-    g_get_current_time(&rj->delivery);
+    gettimeofday(&rj->delivery, NULL);
     job_set_elapse_time(s, rj, AVAHI_RESPONSE_SUPPRESS_MSEC, 0);
 }