From: Amos Jeffries Date: Fri, 25 Jul 2014 12:01:42 +0000 (-0700) Subject: Optimize Comm::Connection IP::address setting X-Git-Tag: SQUID_3_5_0_1~133 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7fb5be3e1ecbb04d42f8c2233cf15e251832d1e5;p=thirdparty%2Fsquid.git Optimize Comm::Connection IP::address setting Use an inline setter to set both local and remote IP address values in one call. --- diff --git a/src/comm/Connection.cc b/src/comm/Connection.cc index 21779976fb..5c03d79d75 100644 --- a/src/comm/Connection.cc +++ b/src/comm/Connection.cc @@ -45,8 +45,7 @@ Comm::Connection::copyDetails() const { ConnectionPointer c = new Comm::Connection; - c->local = local; - c->remote = remote; + c->setAddrs(local, remote); c->peerType = peerType; c->tos = tos; c->nfmark = nfmark; diff --git a/src/comm/Connection.h b/src/comm/Connection.h index 5b700c7fc2..e929c03d0e 100644 --- a/src/comm/Connection.h +++ b/src/comm/Connection.h @@ -104,6 +104,11 @@ public: /** determine whether this object describes an active connection or not. */ bool isOpen() const { return (fd >= 0); } + /** Alter the stored IP address pair. + * WARNING: Does not ensure matching IPv4/IPv6 are supplied. + */ + void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;} + /** retrieve the CachePeer pointer for use. * The caller is responsible for all CBDATA operations regarding the * used of the pointer returned. diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 1088ec02ac..d112496f43 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -899,15 +899,12 @@ idnsInitVC(int nsv) Comm::ConnectionPointer conn = new Comm::Connection(); if (!Config.Addrs.udp_outgoing.isNoAddr()) - conn->local = Config.Addrs.udp_outgoing; + conn->setAddrs(Config.Addrs.udp_outgoing, nameservers[nsv].S); else - conn->local = Config.Addrs.udp_incoming; + conn->setAddrs(Config.Addrs.udp_incoming, nameservers[nsv].S); - conn->remote = nameservers[nsv].S; - - if (conn->remote.isIPv4()) { + if (conn->remote.isIPv4()) conn->local.setIPv4(); - } AsyncCall::Pointer call = commCbCall(78,3, "idnsInitVCConnected", CommConnectCbPtrFun(idnsInitVCConnected, vc)); diff --git a/src/ftp.cc b/src/ftp.cc index 1f8dd02ada..0735e2f80a 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -2468,9 +2468,8 @@ ftpReadEPSV(FtpStateData* ftpState) // Generate a new data channel descriptor to be opened. Comm::ConnectionPointer conn = new Comm::Connection; - conn->local = ftpState->ctrl.conn->local; + conn->setAddrs(ftpState->ctrl.conn->local, ftpState->ctrl.conn->remote); conn->local.port(0); - conn->remote = ftpState->ctrl.conn->remote; conn->remote.port(port); conn->tos = ftpState->ctrl.conn->tos; conn->nfmark = ftpState->ctrl.conn->nfmark; @@ -2724,9 +2723,8 @@ ftpReadPasv(FtpStateData * ftpState) ftpState->ctrl.last_command = xstrdup("Connect to server data port"); Comm::ConnectionPointer conn = new Comm::Connection; - conn->local = ftpState->ctrl.conn->local; + conn->setAddrs(ftpState->ctrl.conn->local, ipaddr); conn->local.port(0); - conn->remote = ipaddr; conn->remote.port(port); debugs(9, 3, HERE << "connecting to " << conn->remote);