]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Further tweaks on pconn keying. plus doc updates
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 2 Oct 2010 16:34:53 +0000 (05:34 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 2 Oct 2010 16:34:53 +0000 (05:34 +1300)
src/pconn.cc
src/pconn.h

index 8082d2aff8377ac735fe491592ff29dd07fd6597..defa0fcb93d8b3586b4892e1de71c37b6be595b9 100644 (file)
@@ -76,21 +76,8 @@ int
 IdleConnList::findIndex(const Comm::ConnectionPointer &conn)
 {
     for (int index = nfds - 1; index >= 0; --index) {
-
-        // remote IPs dont match.
-        if (conn->remote != theList[index]->remote)
-            continue;
-
-        // local end port is required, but dont match.
-        if (conn->local.GetPort() > 0 && conn->local.GetPort() != theList[index]->local.GetPort())
-            continue;
-
-        // local address is required, but does not match.
-        if (!conn->local.IsAnyAddr() && conn->local != theList[index]->local)
-            continue;
-
-        // finally, a match
-        return index;
+        if (conn->fd == theList[index]->fd)
+            return index;
     }
 
     return -1;
@@ -156,17 +143,29 @@ IdleConnList::push(const Comm::ConnectionPointer &conn)
  * quite a bit of CPU. Just keep it in mind.
  */
 Comm::ConnectionPointer
-IdleConnList::findUseable()
+IdleConnList::findUseable(const Comm::ConnectionPointer &key)
 {
     assert(nfds);
 
     for (int i=nfds-1; i>=0; i--) {
-        if (!comm_has_pending_read_callback(theList[i]->fd)) {
-            return theList[i];
-        }
+
+        // callback pending indicates that remote end of the conn has just closed.
+        if (comm_has_pending_read_callback(theList[i]->fd))
+            continue;
+
+        // local end port is required, but dont match.
+        if (conn->local.GetPort() > 0 && conn->local.GetPort() != theList[index]->local.GetPort())
+            continue;
+
+        // local address is required, but does not match.
+        if (!conn->local.IsAnyAddr() && conn->local.matchIPAddr(theList[index]->local) != 0)
+            continue;
+
+        // finally, a match
+        return theList[i];
     }
 
-    return Comm::ConnectionPointer();
+    return key;
 }
 
 void
@@ -314,7 +313,7 @@ PconnPool::pop(Comm::ConnectionPointer &destLink, const char *domain, bool isRet
         debugs(48, 3, "PconnPool::pop: found " << hashKeyStr(&list->hash) << (isRetriable?"(to use)":"(to kill)") );
     }
 
-    Comm::ConnectionPointer temp = list->findUseable(); // search from the end. skip pending reads.
+    Comm::ConnectionPointer temp = list->findUseable(destLink);
 
     if (Comm::IsConnOpen(temp)) {
         list->clearHandlers(temp);
index 0186d31bdc74b1b1b243e282a528f2b5bbeb74dd..fcca0dc66ea4e03e1dde34641dba2e5e093d6578 100644 (file)
@@ -40,6 +40,8 @@ public:
     int findIndex(const Comm::ConnectionPointer &conn); ///< search from the end of array
 
     /**
+     * Search the list for an existing connection. Matches by FD.
+     *
      * \retval false  The connection does not currently exist in the list.
      *                We seem to have hit and lost a race condition.
      *                Nevermind, but MUST NOT do anything with the raw FD.
@@ -47,7 +49,13 @@ public:
     bool remove(const Comm::ConnectionPointer &conn);
 
     void push(const Comm::ConnectionPointer &conn);
-    Comm::ConnectionPointer findUseable();     ///< find first from the end not pending read fd.
+
+    /** Search the list for a connection which matches the 'key' details.
+     * The list is created based on remote IP:port hash. This further filters
+     * the choices based on specific local-end details requested.
+     * If nothing usable is found the key is returned unchanged.
+     */
+    Comm::ConnectionPointer findUseable(const Comm::ConnectionPointer &key);
     void clearHandlers(const Comm::ConnectionPointer &conn);
 
 private: