libev/c-ares migration: unstack out ouf c-ares before querying new requests
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 30 Jan 2011 14:27:29 +0000 (15:27 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 30 Jan 2011 14:27:29 +0000 (15:27 +0100)
  - we use the c-ares callback to parse the DNS reply and put the reply to our callback
  - we then set a zero-timer with the call to continue our flow
  - we return / unstack c-ares
  - we then do the a/aaaa record lookup without having another ares lookup in our stack
this circumvents double dns lookups.

citadel/event_client.c
citadel/event_client.h
citadel/modules/c-ares-dns/serv_c-ares-dns.c
citadel/modules/smtp/serv_smtpeventclient.c
citadel/modules/smtp/serv_smtpqueue.c

index 4ba983220e947352014fea149c83082b72872a7e..b45367d08f71ac784ad9960c2602a34f8fbbe916 100644 (file)
@@ -336,7 +336,12 @@ IO_recv_callback(struct ev_loop *loop, ev_io *watcher, int revents)
        }
 }
 
-
+void
+IO_postdns_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
+{
+       AsyncIO *IO = watcher->data;
+       IO->PostDNS(IO);
+}
 
 eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_rw_timeout)
 {
index 9abda5329aa9f27d927d3fcdd223db25ce8e37a6..79eda639b7726060b997d3ec43eaf23c661711c8 100644 (file)
@@ -38,7 +38,8 @@ struct AsyncIO {
                eNextState NextState;
 
        ev_timer conn_fail, 
-               rw_timeout;
+               rw_timeout,
+               unwind_stack_timeout;
        ev_io recv_event, 
                send_event, 
                conn_event;
@@ -92,8 +93,10 @@ eNextState InitEventIO(AsyncIO *IO,
                       double conn_timeout, 
                       double first_rw_timeout,
                       int ReadFirst);
+void IO_postdns_callback(struct ev_loop *loop, ev_timer *watcher, int revents);
 
 int QueueQuery(ns_type Type, char *name, AsyncIO *IO, IO_CallBack PostDNS);
+void QueryCbDone(AsyncIO *IO);
 
 void StopClient(AsyncIO *IO);
 
index 5f8426f9894731910675c94ff78c99ce3ddd537c..de124f64b2191c4776785dcad3cfc42e2c447ee1 100644 (file)
@@ -218,9 +218,19 @@ void QueryCb(void *arg,
        IO->DNSStatus = status;
        if (status == ARES_SUCCESS)
                IO->DNS_CB(arg, abuf, alen);
+       else
+               IO->DNSStatus = status;
 ///    ev_io_stop(event_base, &IO->dns_io_event);
-               
-       IO->PostDNS(IO);
+       
+       ev_timer_init(&IO->unwind_stack_timeout,
+                     IO_postdns_callback, 0.0, 0);
+       IO->unwind_stack_timeout.data = IO;
+       ev_timer_start(event_base, &IO->unwind_stack_timeout);
+}
+
+void QueryCbDone(AsyncIO *IO)
+{
+       ev_timer_stop(event_base, &IO->unwind_stack_timeout);
 }
 
 
index 7eb42248cee393a9d832b3584fe1e5d07585da34..133ee8fbeba6b6787858b5dfa3080841b6236015 100644 (file)
@@ -421,6 +421,8 @@ eNextState smtp_resolve_mx_done(AsyncIO *IO)
 {
        SmtpOutMsg * SendMsg = IO->Data;
 
+       QueryCbDone(IO);
+
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
 
        SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
index 5ae9796bdd0f703c6cad3eb33c7b7b5783488a0d..591918ea200b5d3fc551e75e935a034770523841 100644 (file)
@@ -420,7 +420,7 @@ StrBuf *smtp_load_msg(OneQueItem *MyQItem, int n)
        if ((StrLength(SendMsg) > 0) && 
            ChrPtr(SendMsg)[StrLength(SendMsg) - 1] != '\n') {
                CtdlLogPrintf(CTDL_WARNING, 
-                             "SMTP client[%ld]: Possible problem: message did not "
+                             "SMTP client[%d]: Possible problem: message did not "
                              "correctly terminate. (expecting 0x10, got 0x%02x)\n",
                              MsgCount, //yes uncool, but best choice here... 
                              ChrPtr(SendMsg)[StrLength(SendMsg) - 1] );