]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update names for Comm Paths/paths - new ConnectionList/serverDestinations
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 22 Jul 2010 14:39:27 +0000 (02:39 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 22 Jul 2010 14:39:27 +0000 (02:39 +1200)
src/PeerSelectState.h
src/comm/forward.h
src/forward.cc
src/forward.h
src/peer_select.cc
src/tunnel.cc

index c25cf33044d4ed49488f66e4faa3325d80fee206..92944f5a7239d094d2a1b143f1575e6f3d063628 100644 (file)
@@ -43,9 +43,9 @@
 class HttpRequest;
 class StoreEntry;
 
-typedef void PSC(Comm::Paths *, void *);
+typedef void PSC(Comm::ConnectionList *, void *);
 
-SQUIDCEXTERN void peerSelect(Comm::Paths *, HttpRequest *, StoreEntry *, PSC *, void *data);
+SQUIDCEXTERN void peerSelect(Comm::ConnectionList *, HttpRequest *, StoreEntry *, PSC *, void *data);
 SQUIDCEXTERN void peerSelectInit(void);
 
 /**
@@ -79,7 +79,7 @@ public:
     PSC *callback;
     void *callback_data;
 
-    Comm::Paths *paths;    ///< the callers paths array. to be filled with our final results.
+    Comm::ConnectionList *paths;    ///< the callers paths array. to be filled with our final results.
     FwdServer *servers;    ///< temporary linked list of peers we will pass back.
 
     /*
index 5f0c8a7249befd6a2a35d82341aaa7ea2aa39ec1..b9a1af499cf2c8c8bac2a4de4f096d16cbd29638 100644 (file)
@@ -10,7 +10,7 @@ class Connection;
 
 typedef RefCount<Comm::Connection> ConnectionPointer;
 
-typedef Vector<Comm::ConnectionPointer> Paths;
+typedef Vector<Comm::ConnectionPointer> ConnectionList;
 
 }; // namespace Comm
 
index e8b6daa31e2dd544dc99f5298823a190b2c37139..57539cce999aff579db6111f3e19f3f8f813273d 100644 (file)
@@ -83,7 +83,7 @@ FwdState::abort(void* d)
     if (fwd->isServerConnectionOpen()) {
         comm_remove_close_handler(fwd->serverConnection()->fd, fwdServerClosedWrapper, fwd);
     }
-    fwd->paths.clean();
+    fwd->serverDestinations.clean();
     fwd->self = NULL;
 }
 
@@ -95,7 +95,7 @@ FwdState::FwdState(int fd, StoreEntry * e, HttpRequest * r)
     client_fd = fd;
     request = HTTPMSGLOCK(r);
     start_t = squid_curtime;
-
+    serverDestinations.reserve(Config.forward_max_tries);
     e->lock();
     EBIT_SET(e->flags, ENTRY_FWD_HDR_WAIT);
 }
@@ -113,7 +113,7 @@ void FwdState::start(Pointer aSelf)
     // Otherwise we are going to leak our object.
 
     entry->registerAbort(FwdState::abort, this);
-    peerSelect(&paths, request, entry, fwdStartCompleteWrapper, this);
+    peerSelect(&serverDestinations, request, entry, fwdStartCompleteWrapper, this);
 }
 
 void
@@ -173,10 +173,10 @@ FwdState::~FwdState()
     if (isServerConnectionOpen()) {
         comm_remove_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);
         debugs(17, 3, HERE << "closing FD " << serverConnection()->fd);
-        serverConnection()->close();
+        serverConn->close();
     }
 
-    paths.clean();
+    serverDestinations.clean();
 
     debugs(17, 3, HERE << "FwdState destructor done");
 }
@@ -266,7 +266,7 @@ FwdState::startComplete()
 {
     debugs(17, 3, HERE << entry->url() );
 
-    if (paths.size() > 0) {
+    if (serverDestinations.size() > 0) {
         connectStart();
     } else {
         debugs(17, 3, HERE << entry->url()  );
@@ -295,12 +295,13 @@ FwdState::fail(ErrorState * errorState)
  * Frees fwdState without closing FD or generating an abort
  */
 void
-FwdState::unregister(Comm::ConnectionPointer conn)
+FwdState::unregister(Comm::ConnectionPointer &conn)
 {
     debugs(17, 3, HERE << entry->url() );
     assert(serverConnection() == conn);
     assert(conn->isOpen());
     comm_remove_close_handler(conn->fd, fwdServerClosedWrapper, this);
+    serverConn = NULL;
 }
 
 // Legacy method to be removed in favor of the above as soon as possible
@@ -309,9 +310,7 @@ FwdState::unregister(int fd)
 {
     debugs(17, 3, HERE << entry->url() );
     assert(fd == serverConnection()->fd);
-    assert(fd > -1);
-    comm_remove_close_handler(fd, fwdServerClosedWrapper, this);
-    serverConnection()->fd = -1;
+    unregister(serverConn);
 }
 
 /**
@@ -336,7 +335,7 @@ FwdState::complete()
         debugs(17, 3, HERE << "re-forwarding " << entry->getReply()->sline.status << " " << entry->url());
 
         if (isServerConnectionOpen())
-            unregister(serverConnection());
+            unregister(serverConn);
 
         entry->reset();
 
@@ -360,7 +359,7 @@ FwdState::complete()
 /**** CALLBACK WRAPPERS ************************************************************/
 
 static void
-fwdStartCompleteWrapper(Comm::Paths * unused, void *data)
+fwdStartCompleteWrapper(Comm::ConnectionList * unused, void *data)
 {
     FwdState *fwd = (FwdState *) data;
     fwd->startComplete();
@@ -502,9 +501,9 @@ FwdState::retryOrBail()
     if (checkRetry()) {
         debugs(17, 3, HERE << "re-forwarding (" << n_tries << " tries, " << (squid_curtime - start_t) << " secs)");
 
-        paths.shift(); // last one failed. try another.
+        serverDestinations.shift(); // last one failed. try another.
 
-        if (paths.size() > 0) {
+        if (serverDestinations.size() > 0) {
             /* Ditch error page if it was created before.
              * A new one will be created if there's another problem */
             if (err) {
@@ -515,7 +514,7 @@ FwdState::retryOrBail()
             connectStart();
             return;
         }
-        // else bail. no more paths possible to try.
+        // else bail. no more serverDestinations possible to try.
     }
 
     if (!err && shutting_down) {
@@ -573,7 +572,7 @@ FwdState::negotiateSSL(int fd)
                 peerConnectFailed(serverConnection()->getPeer());
             }
 
-            serverConnection()->close();
+            serverConn->close();
             return;
         }
     }
@@ -662,16 +661,18 @@ FwdState::connectDone(Comm::ConnectionPointer &conn, comm_err_t status, int xerr
         fail(anErr);
 
         /* it might have been a timeout with a partially open link */
-        if (paths.size() > 0) {
-            if (serverConnection()->getPeer())
-                peerConnectFailed(serverConnection()->getPeer());
+        if (conn != NULL) {
+            if (conn->getPeer())
+                peerConnectFailed(conn->getPeer());
 
-            serverConnection()->close();
+            conn->close();
         }
         retryOrBail();
         return;
     }
 
+    serverConn = conn;
+
 #if REDUNDANT_NOW
     if (Config.onoff.log_ip_on_direct && serverConnection()->peerType == HIER_DIRECT)
         updateHierarchyInfo();
@@ -712,13 +713,12 @@ FwdState::connectTimeout(int fd)
         fail(anErr);
 
         /* This marks the peer DOWN ... */
-        if (paths.size() > 0)
-            if (serverConnection()->getPeer())
+        if (serverConnection() != NULL && serverConnection()->getPeer())
                 peerConnectFailed(serverConnection()->getPeer());
     }
 
     if (isServerConnectionOpen()) {
-        serverConnection()->close();
+        serverConn->close();
     }
 }
 
@@ -756,26 +756,25 @@ FwdState::connectStart()
     if (serverConnection()->peerType == PINNED) {
         ConnStateData *pinned_connection = request->pinnedConnection();
         assert(pinned_connection);
-        serverConnection()->fd = pinned_connection->validatePinnedConnection(request, serverConnection()->getPeer());
+        serverConn->fd = pinned_connection->validatePinnedConnection(request, serverConnection()->getPeer());
         if (isServerConnectionOpen()) {
             pinned_connection->unpinConnection();
 #if 0
             if (!serverConnection()->getPeer())
-                serverConnection()->peerType = HIER_DIRECT;
+                serverConn->peerType = HIER_DIRECT;
 #endif
             n_tries++;
             request->flags.pinned = 1;
             if (pinned_connection->pinnedAuth())
                 request->flags.auth = 1;
             updateHierarchyInfo();
-            Comm::ConnectionPointer conn = serverConnection();
-            FwdState::connectDone(conn, COMM_OK, 0);
+            FwdState::connectDone(serverConn, COMM_OK, 0);
             return;
         }
         /* Failure. Fall back on next path */
         debugs(17,2,HERE << " Pinned connection " << pinned_connection << " not valid. Releasing.");
         request->releasePinnedConnection();
-        paths.shift();
+        serverDestinations.shift();
         connectStart();
         return;
     }
@@ -791,16 +790,16 @@ FwdState::connectStart()
     if (serverConnection()->getPeer()) {
         host = serverConnection()->getPeer()->host;
         port = serverConnection()->getPeer()->http_port;
-        serverConnection()->fd = fwdPconnPool->pop(serverConnection()->getPeer()->name,
-                                                   serverConnection()->getPeer()->http_port,
-                                                   request->GetHost(), serverConnection()->local,
-                                                   checkRetriable());
+        serverConn->fd = fwdPconnPool->pop(serverConnection()->getPeer()->name,
+                                           serverConnection()->getPeer()->http_port,
+                                           request->GetHost(), serverConn->local,
+                                           checkRetriable());
     } else {
         host = request->GetHost();
         port = request->port;
-        serverConnection()->fd = fwdPconnPool->pop(host, port, NULL, serverConnection()->local, checkRetriable());
+        serverConn->fd = fwdPconnPool->pop(host, port, NULL, serverConn->local, checkRetriable());
     }
-    serverConnection()->remote.SetPort(port);
+    serverConn->remote.SetPort(port);
 
     if (isServerConnectionOpen()) {
         debugs(17, 3, HERE << "reusing pconn FD " << serverConnection()->fd);
@@ -822,8 +821,7 @@ FwdState::connectStart()
 #endif
 
     AsyncCall::Pointer call = commCbCall(17,3, "fwdConnectDoneWrapper", CommConnectCbPtrFun(fwdConnectDoneWrapper, this));
-    Comm::ConnectionPointer conn = serverConnection();
-    Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, ctimeout);
+    Comm::ConnOpener *cs = new Comm::ConnOpener(serverDestinations[0], call, ctimeout);
     cs->setHost(host);
     AsyncJob::AsyncStart(cs);
 }
@@ -953,7 +951,7 @@ FwdState::dispatch()
              */
             flags.dont_retry = 1;
             if (isServerConnectionOpen()) {
-                serverConnection()->close();
+                serverConn->close();
             }
             break;
         }
@@ -996,9 +994,9 @@ FwdState::reforward()
     if (request->bodyNibbled())
         return 0;
 
-    paths.shift();
+    serverDestinations.shift();
 
-    if (paths.size() > 0) {
+    if (serverDestinations.size() > 0) {
         debugs(17, 3, HERE << "No alternative forwarding paths left");
         return 0;
     }
@@ -1073,7 +1071,7 @@ FwdState::reforwardableStatus(http_status s)
  *  -  address of the client for which we made the connection
  */
 void
-FwdState::pconnPush(Comm::ConnectionPointer conn, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr)
+FwdState::pconnPush(Comm::ConnectionPointer &conn, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr)
 {
     if (_peer) {
         fwdPconnPool->push(conn->fd, _peer->name, _peer->http_port, domain, client_addr);
@@ -1146,7 +1144,7 @@ FwdState::updateHierarchyInfo()
 {
     assert(request);
 
-    assert(paths.size() > 0);
+    assert(serverDestinations.size() > 0);
 
     char nextHop[256];
 
index f26fe263d59b437f45ea7ee7bce4343c66a6b256..d0885e6d18be5fdf6f4480c4c27e8ceb341a0f9c 100644 (file)
@@ -22,7 +22,7 @@ public:
     static void fwdStart(int fd, StoreEntry *, HttpRequest *);
     void startComplete();
     void fail(ErrorState *err);
-    void unregister(Comm::ConnectionPointer conn);
+    void unregister(Comm::ConnectionPointer &conn);
     void unregister(int fd);
     void complete();
     void handleUnregisteredServerEnd();
@@ -30,14 +30,14 @@ public:
     bool reforwardableStatus(http_status s);
     void serverClosed(int fd);
     void connectStart();
-    void connectDone(Comm::ConnectionPointer &conn, comm_err_t status, int xerrno);
+    void connectDone(Comm::ConnectionPointer & conn, comm_err_t status, int xerrno);
     void connectTimeout(int fd);
     void initiateSSL();
     void negotiateSSL(int fd);
     bool checkRetry();
     bool checkRetriable();
     void dispatch();
-    void pconnPush(Comm::ConnectionPointer conn, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr);
+    void pconnPush(Comm::ConnectionPointer conn, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr);
 
     bool dontRetry() { return flags.dont_retry; }
 
@@ -48,13 +48,13 @@ public:
     void ftpPasvFailed(bool val) { flags.ftp_pasv_failed = val; }
 
     /** return a ConnectionPointer to the current server connection (may or may not be open) */
-    Comm::ConnectionPointer serverConnection() const { assert(paths.size() > 0); return paths[0]; };
+    Comm::ConnectionPointer const & serverConnection() const { return serverConn; };
 
     /** test if the current server connection is open */
     bool isServerConnectionOpen() const {
-        if (paths.size() > 0 && serverConnection()->fd >= 0)
-            assert(fd_table[serverConnection()->fd].flags.open == serverConnection()->isOpen());
-        return (paths.size() > 0 && serverConnection()->isOpen());
+        if (serverConn != NULL && serverConn->isOpen())
+            assert(fd_table[serverConn->fd].flags.open == serverConn->isOpen());
+        return (serverConn != NULL && serverConn->isOpen());
     };
 
 private:
@@ -99,7 +99,9 @@ private:
     } flags;
 
     /** connections to open, in order, until successful */
-    Comm::Paths paths;
+    Comm::ConnectionList serverDestinations;
+
+    Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
 
     // NP: keep this last. It plays with private/public
     CBDATA_CLASS2(FwdState);
index 5bac2340e1768561497db1642a2ee27c4f657685..7a7234cd95d8cce1d955966c3ced519c1df0b0c3 100644 (file)
@@ -124,7 +124,7 @@ peerSelectIcpPing(HttpRequest * request, int direct, StoreEntry * entry)
 
 
 void
-peerSelect(Comm::Paths * paths,
+peerSelect(Comm::ConnectionList * paths,
            HttpRequest * request,
            StoreEntry * entry,
            PSC * callback,
index e1b9f75b6ba543fe9fc9b1a0c9d736eb77a09c50..564bc08735285e4868a9f88c44a52dd615d24145 100644 (file)
@@ -68,7 +68,7 @@ public:
     char *host;                        /* either request->host or proxy host */
     u_short port;
     HttpRequest *request;
-    Comm::Paths paths;
+    Comm::ConnectionList serverDestinations;
 
     class Connection
     {
@@ -79,7 +79,7 @@ public:
         ~Connection();
         int const & fd() const { return fd_;}
 
-        void fd(int const newFD);
+        void fd(int newFd);
         int bytesWanted(int lower=0, int upper = INT_MAX) const;
         void bytesIn(int const &);
 #if DELAY_POOLS
@@ -176,7 +176,7 @@ tunnelStateFree(TunnelStateData * tunnelState)
     assert(tunnelState != NULL);
     assert(tunnelState->noConnections());
     safe_free(tunnelState->url);
-    tunnelState->paths.clean();
+    tunnelState->serverDestinations.clean();
     tunnelState->host = NULL;
     HTTPMSGUNLOCK(tunnelState->request);
     delete tunnelState;
@@ -543,11 +543,11 @@ tunnelConnectDone(Comm::ConnectionPointer &conn, comm_err_t status, int xerrno,
         /* At this point only the TCP handshake has failed. no data has been passed.
          * we are allowed to re-try the TCP-level connection to alternate IPs for CONNECT.
          */
-        tunnelState->paths.shift();
-        if (status != COMM_TIMEOUT && tunnelState->paths.size() > 0) {
+        tunnelState->serverDestinations.shift();
+        if (status != COMM_TIMEOUT && tunnelState->serverDestinations.size() > 0) {
             /* Try another IP of this destination host */
             AsyncCall::Pointer call = commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone, tunnelState));
-            Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->paths[0], call, Config.Timeout.connect);
+            Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->serverDestinations[0], call, Config.Timeout.connect);
             cs->setHost(tunnelState->url);
             AsyncJob::AsyncStart(cs);
         } else {
@@ -643,7 +643,7 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr)
                    tunnelTimeout,
                    tunnelState);
 
-    peerSelect(&(tunnelState->paths), request,
+    peerSelect(&(tunnelState->serverDestinations), request,
                NULL,
                tunnelPeerSelectComplete,
                tunnelState);
@@ -684,7 +684,7 @@ tunnelProxyConnected(int fd, void *data)
 }
 
 static void
-tunnelPeerSelectComplete(Comm::Paths *peer_paths, void *data)
+tunnelPeerSelectComplete(Comm::ConnectionList *peer_paths, void *data)
 {
     TunnelStateData *tunnelState = (TunnelStateData *)data;
     HttpRequest *request = tunnelState->request;
@@ -700,7 +700,7 @@ tunnelPeerSelectComplete(Comm::Paths *peer_paths, void *data)
     }
 
     AsyncCall::Pointer call = commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone, tunnelState));
-    Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->paths[0], call, Config.Timeout.connect);
+    Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->serverDestinations[0], call, Config.Timeout.connect);
     cs->setHost(tunnelState->url);
     AsyncJob::AsyncStart(cs);
 }