]> code.citadel.org Git - citadel.git/blobdiff - citadel/event_client.c
libev/c-ares migration: unstack out ouf c-ares before querying new requests
[citadel.git] / citadel / event_client.c
index 4dca578f7232122e63c0ab301d7cd5b6e1cfc5c8..b45367d08f71ac784ad9960c2602a34f8fbbe916 100644 (file)
@@ -119,7 +119,6 @@ void FreeAsyncIOContents(AsyncIO *IO)
        FreeStrBuf(&IO->IOBuf);
        FreeStrBuf(&IO->SendBuf.Buf);
        FreeStrBuf(&IO->RecvBuf.Buf);
-       ares_destroy(IO->DNSChannel);
 }
 
 
@@ -137,6 +136,12 @@ void ShutDownCLient(AsyncIO *IO)
                IO->SendBuf.fd = 0;
                IO->RecvBuf.fd = 0;
        }
+       if (IO->DNSChannel != NULL) {
+               ares_destroy(IO->DNSChannel);
+               ev_io_stop(event_base, &IO->dns_recv_event);
+               ev_io_stop(event_base, &IO->dns_send_event);
+               IO->DNSChannel = NULL;
+       }
        assert(IO->Terminate);
        IO->Terminate(IO);
        
@@ -331,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)
 {
@@ -379,9 +389,9 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
        IO->conn_fail.data = IO;
        ev_timer_init(&IO->rw_timeout, IO_Timout_callback, first_rw_timeout, 0);
        IO->rw_timeout.data = IO;
-       ///struct sockaddr_in *addr = &IO->Addr;
+
        if (IO->IP6)
-               rc = connect(IO->sock, &IO->Addr, sizeof(struct in6_addr));
+               rc = connect(IO->sock, &IO->Addr, sizeof(struct sockaddr_in6));
        else
                rc = connect(IO->sock, (struct sockaddr_in *)&IO->Addr, sizeof(struct sockaddr_in));
 
@@ -430,7 +440,5 @@ eNextState InitEventIO(AsyncIO *IO,
        else {
                IO->NextState = eSendReply;
        }
-       IO->IP6 = IO->HEnt->h_addrtype == AF_INET6;
-//     IO->res = HEnt->h_addr_list[0];
        return event_connect_socket(IO, conn_timeout, first_rw_timeout);
 }