Bryan Drewery 21 лет назад
Родитель
Сommit
27ab976f7a
2 измененных файлов с 29 добавлено и 1 удалено
  1. 27 0
      src/adns.c
  2. 2 1
      src/egg_timer.c

+ 27 - 0
src/adns.c

@@ -19,6 +19,7 @@ typedef struct dns_query {
 	dns_callback_t callback;
 	time_t time;
 	int id;
+        int timer_id;
 	int remaining;
 	char *query;
 	void *client_data;
@@ -136,6 +137,20 @@ static struct dcc_table dns_handler = {
   NULL,
 };
 
+static void async_timeout(void *client_data)
+{
+  int id = (int) client_data;
+  dns_query_t *q = NULL;
+
+  for (q = query_head; q; q = q->next)
+    if (q->id == id) break;
+
+  if (!q) return;
+
+
+  sdprintf("%s failed!", q->query);
+}
+
 static void answer_init(dns_answer_t *answer)
 {
 	memset(answer, 0, sizeof(*answer));
@@ -260,6 +275,14 @@ int egg_dns_lookup(const char *host, int timeout, dns_callback_t callback, void
 	/* Allocate our query struct. */
         q = alloc_query(client_data, callback, host);
 
+        /* setup a timer to detect dead ns */
+//        egg_timeval_t howlong;
+
+//        howlong.sec = async_resolve_timeout;
+//        howlong.usec = 0;
+
+//        q->timer_id = timer_create_complex(&howlong, host, (Function) async_timeout, (void *) q->id, 0);
+
 	/* Send the ipv4 query. */
 	q->remaining = 1;
 	len = make_header(buf, q->id);
@@ -621,6 +644,10 @@ static void parse_reply(char *response, int nbytes)
 		prev = q;
 	}
 	if (!q) return;
+        
+        /* destroy our async timeout */
+//        timer_destroy(q->timer_id);
+
 	/* Pass over the questions. */
 	for (i = 0; i < header.question_count; i++) {
 		ptr += skip_name(ptr);

+ 2 - 1
src/egg_timer.c

@@ -214,13 +214,14 @@ int timer_run()
 
 			/* Add it back into the list. */
 			timer_add_to_list(timer);
+
+			timer->called++;
 		}
 		else {
 			if (timer->name) free(timer->name);
 			free(timer);
 		}
 
-		if (timer) timer->called++;
 		callback(client_data);
 	}
 	return(0);