]> 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 c4218eb1ad4b77e49e2394962e2ad87a3340f44c..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
@@ -44,7 +45,7 @@ struct AvahiResponseJob {
     AvahiTimeEvent *time_event;
     
     AvahiResponseJobState state;
-    GTimeVal delivery;
+    struct timeval delivery;
 
     AvahiRecord *record;
     gboolean flush_cache;
@@ -107,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);
@@ -133,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) {
@@ -233,7 +234,7 @@ static void send_response_packet(AvahiResponseScheduler *s, AvahiResponseJob *rj
         if (!packet_add_response_job(s, p, rj)) {
             avahi_dns_packet_free(p);
 
-            g_warning("Record too large, cannot send");
+            avahi_log_warn("Record too large, cannot send");
             job_mark_done(s, rj);
             return;
         }
@@ -283,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;
@@ -326,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) {
 
-        g_message("Response suppressed by known answer suppression.");
+/*         avahi_log_debug("Response suppressed by known answer suppression.");  */
         return FALSE;
     }
 
@@ -349,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)) {
-            g_message("Response suppressed by local duplicate suppression (history)");
+/*             avahi_log_debug("Response suppressed by local duplicate suppression (history)");  */
             return FALSE;
         }
 
@@ -360,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))) {
-        g_message("Response suppressed by local duplicate suppression (scheduled)");
+/*          avahi_log_debug("Response suppressed by local duplicate suppression (scheduled)"); */
 
         /* Update a little ... */
 
@@ -384,7 +392,7 @@ gboolean avahi_response_scheduler_post(AvahiResponseScheduler *s, AvahiRecord *r
 
         return TRUE;
     } else {
-        g_message("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);
@@ -414,7 +422,7 @@ void avahi_response_scheduler_incoming(AvahiResponseScheduler *s, AvahiRecord *r
             record->ttl >= rj->record->ttl/2) {     /* sensible TTL */
 
             /* A matching entry was found, so let's mark it done */
-            g_message("Response suppressed by distributed duplicate suppression");
+/*             avahi_log_debug("Response suppressed by distributed duplicate suppression"); */
             job_mark_done(s, rj);
         }
 
@@ -432,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);
 }
 
@@ -450,7 +458,7 @@ void avahi_response_scheduler_suppress(AvahiResponseScheduler *s, AvahiRecord *r
             record->ttl >= rj->record->ttl/2) {                                  /* sensible TTL */
 
             /* A matching entry was found, so let's drop it */
-            g_message("Known answer suppression active!");
+/*             avahi_log_debug("Known answer suppression active!"); */
             job_free(s, rj);
         }
     }
@@ -469,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);
 }