]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Optimize Comm::Connection IP::address setting
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 25 Jul 2014 12:01:42 +0000 (05:01 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 25 Jul 2014 12:01:42 +0000 (05:01 -0700)
Use an inline setter to set both local and remote IP address values in
one call.

src/comm/Connection.cc
src/comm/Connection.h
src/dns_internal.cc
src/ftp.cc

index 21779976fbd098dedc94e762c2086f009ff87e71..5c03d79d7559431f10f184faf976ff48879f099d 100644 (file)
@@ -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;
index 5b700c7fc2b15f664d16aed819b00c8c2707305b..e929c03d0e1e59d709686b38617e4c8ab4b37598 100644 (file)
@@ -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.
index 1088ec02ac1d2c40e13b2d963e785f2e676433e3..d112496f43b0f5cb51624c0d90dea5440c19366c 100644 (file)
@@ -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));
 
index 1f8dd02ada13a307e536b7956c137888954edad3..0735e2f80a2a7828fa65523b4c5e33aa3a1ef05a 100644 (file)
@@ -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);