From: Amos Jeffries Date: Sat, 4 Sep 2010 15:09:33 +0000 (+1200) Subject: Merge from trunk X-Git-Tag: take08~55^2~124^2~71 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=31445f42e3c970ba413e8b88b1f1382b3ae97976;p=thirdparty%2Fsquid.git Merge from trunk --- 31445f42e3c970ba413e8b88b1f1382b3ae97976 diff --cc src/dns_internal.cc index d021190b2e,b2668dc477..259e688c60 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@@ -705,13 -704,16 +705,17 @@@ idnsDoSendQueryVC(nsvc *vc } static void - idnsInitVCConnected(const Comm::ConnectionPointer &conn, comm_err_t status, int xerrno, void *data) -idnsInitVCConnected(int fd, const DnsLookupDetails &details, comm_err_t status, int xerrno, void *data) ++idnsInitVCConnected(const Comm::ConnectionPointer &conn, const DnsLookupDetails &details, comm_err_t status, int xerrno, void *data) { nsvc * vc = (nsvc *)data; - if (status != COMM_OK) { + if (status != COMM_OK || !conn) { - char buf[MAX_IPSTRLEN]; - debugs(78, DBG_IMPORTANT, "Failed to connect to nameserver " << nameservers[vc->ns].S.NtoA(buf,MAX_IPSTRLEN) << " using TCP!"); + char buf[MAX_IPSTRLEN] = ""; + if (vc->ns < nns) + nameservers[vc->ns].S.NtoA(buf,MAX_IPSTRLEN); + debugs(78, 1, HERE << "Failed to connect to nameserver " << buf << " using TCP: " << details); - comm_close(fd); ++ Comm::ConnectionPOinter nonConst = conn; ++ nonConst->close(); return; } @@@ -736,27 -736,44 +741,28 @@@ idnsVCClosed(int fd, void *data static void idnsInitVC(int ns) { - char buf[MAX_IPSTRLEN]; - nsvc *vc = cbdataAlloc(nsvc); + assert(ns < nns); nameservers[ns].vc = vc; vc->ns = ns; - - Ip::Address addr; - - if (!Config.Addrs.udp_outgoing.IsNoAddr()) - addr = Config.Addrs.udp_outgoing; - else - addr = Config.Addrs.udp_incoming; - - if (nameservers[ns].S.IsIPv4() && !addr.SetIPv4()) { - debugs(31, DBG_CRITICAL, "ERROR: Cannot contact DNS nameserver " << nameservers[ns].S << " from " << addr); - addr.SetAnyAddr(); - addr.SetIPv4(); - } - vc->queue = new MemBuf; - vc->msg = new MemBuf; + vc->busy = 1; - vc->fd = comm_open(SOCK_STREAM, - IPPROTO_TCP, - addr, - COMM_NONBLOCKING, - "DNS TCP Socket"); + Comm::ConnectionPointer conn = new Comm::Connection; - if (vc->fd < 0) - fatal("Could not create a DNS socket"); + if (!Config.Addrs.udp_outgoing.IsNoAddr()) + conn->local = Config.Addrs.udp_outgoing; + else + conn->local = Config.Addrs.udp_incoming; - comm_add_close_handler(vc->fd, idnsVCClosed, vc); + conn->remote = nameservers[ns].S; - vc->busy = 1; + AsyncCall::Pointer call = commCbCall(78,3, "idnsInitVCConnected", CommConnectCbPtrFun(idnsInitVCConnected, vc)); - commConnectStart(vc->fd, nameservers[ns].S.NtoA(buf,MAX_IPSTRLEN), nameservers[ns].S.GetPort(), idnsInitVCConnected, vc); + Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, Config.Timeout.connect); + cs->setHost("DNS TCP Socket"); + AsyncJob::Start(cs); } static void