From: Wilfried Goesgens Date: Sun, 30 Jan 2011 14:27:29 +0000 (+0100) Subject: libev/c-ares migration: unstack out ouf c-ares before querying new requests X-Git-Tag: v8.11~1096 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=757d27c6e4c9eefec77b1b4c4c41ea2a8b312007 libev/c-ares migration: unstack out ouf c-ares before querying new requests - 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. --- diff --git a/citadel/event_client.c b/citadel/event_client.c index 4ba983220..b45367d08 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -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) { diff --git a/citadel/event_client.h b/citadel/event_client.h index 9abda5329..79eda639b 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -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); diff --git a/citadel/modules/c-ares-dns/serv_c-ares-dns.c b/citadel/modules/c-ares-dns/serv_c-ares-dns.c index 5f8426f98..de124f64b 100644 --- a/citadel/modules/c-ares-dns/serv_c-ares-dns.c +++ b/citadel/modules/c-ares-dns/serv_c-ares-dns.c @@ -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); } diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 7eb42248c..133ee8fbe 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -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; diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index 5ae9796bd..591918ea2 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -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] );