From: Amos Jeffries Date: Sat, 2 Oct 2010 16:34:53 +0000 (+1300) Subject: Further tweaks on pconn keying. plus doc updates X-Git-Tag: take08~55^2~124^2~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=139d9221b42874ace6e917dcff735d4e1b19e0ec;p=thirdparty%2Fsquid.git Further tweaks on pconn keying. plus doc updates --- diff --git a/src/pconn.cc b/src/pconn.cc index 8082d2aff8..defa0fcb93 100644 --- a/src/pconn.cc +++ b/src/pconn.cc @@ -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); diff --git a/src/pconn.h b/src/pconn.h index 0186d31bdc..fcca0dc66e 100644 --- a/src/pconn.h +++ b/src/pconn.h @@ -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: