]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
make Comm::Connection ref-counted and fix pconn handling.
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 22 May 2010 06:34:14 +0000 (18:34 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 22 May 2010 06:34:14 +0000 (18:34 +1200)
24 files changed:
include/RefCount.h
src/CommCalls.cc
src/CommCalls.h
src/PeerSelectState.h
src/adaptation/icap/Xaction.cc
src/client_side.cc
src/comm.cc
src/comm.h
src/comm/ConnectStateData.cc
src/comm/ConnectStateData.h
src/comm/Connection.h
src/comm/ListenStateData.cc
src/comm/ListenStateData.h
src/dns_internal.cc
src/forward.cc
src/forward.h
src/ftp.cc
src/http.cc
src/ident/Ident.cc
src/ident/Ident.h
src/neighbors.cc
src/peer_select.cc
src/protos.h
src/tunnel.cc

index f648fe48cf8d7de65925ffe5267056ce3d3c9674..110ca456cd7e8eed13c1ec50a41e2f5a982acba1 100644 (file)
@@ -114,7 +114,7 @@ private:
 struct RefCountable_ {
     RefCountable_():count_(0) {}
 
-    virtual ~RefCountable_() {}
+    virtual ~RefCountable_() { assert(RefCountCount() == 0); }
 
     /* Not private, to allow class hierarchies */
     void RefCountReference() const {
index d4b10a652b8b3abc02d2cd4876c05506be3b8615..ce5b8028ef12c93df847ba033a7e0c60dc539176 100644 (file)
@@ -45,6 +45,7 @@ CommAcceptCbParams::print(std::ostream &os) const
     CommCommonCbParams::print(os);
     if (nfd >= 0)
         os << ", newFD " << nfd;
+    os << ", " << details;
 }
 
 
@@ -71,6 +72,11 @@ void
 CommConnectCbParams::print(std::ostream &os) const
 {
     CommCommonCbParams::print(os);
+    if (conn != NULL)
+      os << ", from my " << conn->local << " to " << conn->remote;
+    else if (paths && paths->size() > 0) {
+        // TODO: for each path. print the to => from path being attempted.
+    }
 }
 
 /* CommIoCbParams */
index d732a7f153d47cf2b836fe39ac3a8a463d6312a6..9dc02f0f03254e4e716c1a3c499ef69d616a5302 100644 (file)
@@ -68,7 +68,7 @@ public:
     void print(std::ostream &os) const;
 
 public:
-    Comm::Connection *details;
+    Comm::Connection::Pointer details;
     int nfd; // TODO: rename to fdNew or somesuch
 };
 
@@ -83,8 +83,8 @@ public:
     void print(std::ostream &os) const;
 
 public:
-    Comm::Connection *conn;
-    Vector<Comm::Connection *> *paths;
+    Comm::Connection::Pointer conn;
+    Vector<Comm::Connection::Pointer> *paths;
 };
 
 // read/write (I/O) parameters
index 6896a1582557df23ee0c0cd9b1f5fc182c32a2e2..e4fb65755f6d7deba6ec680b07f7a84ff0595f05 100644 (file)
@@ -42,9 +42,9 @@
 class HttpRequest;
 class StoreEntry;
 
-typedef void PSC(Vector<Comm::Connection*> *, void *);
+typedef void PSC(Vector<Comm::Connection::Pointer> *, void *);
 
-SQUIDCEXTERN void peerSelect(Vector<Comm::Connection*> *, HttpRequest *, StoreEntry *, PSC *, void *data);
+SQUIDCEXTERN void peerSelect(Vector<Comm::Connection::Pointer> *, HttpRequest *, StoreEntry *, PSC *, void *data);
 SQUIDCEXTERN void peerSelectInit(void);
 
 /**
@@ -78,7 +78,7 @@ public:
     PSC *callback;
     void *callback_data;
 
-    Vector<Comm::Connection*> *paths;  ///< the callers paths array. to be filled with our final results.
+    Vector<Comm::Connection::Pointer> *paths;  ///< the callers paths array. to be filled with our final results.
     FwdServer *servers;                ///< temporary linked list of peers we will pass back.
 
     /*
index 6356d052f2c347ded1a632378307a67c2fef355e..e08d1811801126dd2a1427b051c822622f06856a 100644 (file)
@@ -116,7 +116,7 @@ void Adaptation::Icap::Xaction::openConnection()
 
     disableRetries(); // we only retry pconn failures
 
-    Comm::Connection *conn = new Comm::Connection;
+    Comm::Connection::Pointer conn = new Comm::Connection;
 
     // TODO:  where do we get the DNS info for the ICAP server host ??
     //        Ip::Address will do a BLOCKING lookup if s.cfg().host is a hostname
index 7a53da8454a68408d7d41691cb8daa85b7895984..053caf50bab98a5bc7f639313fa761fc33df8fd5 100644 (file)
@@ -3057,7 +3057,7 @@ connStateCreate(const Ip::Address &peer, const Ip::Address &me, int fd, http_por
 
 /** Handle a new connection on HTTP socket. */
 void
-httpAccept(int sock, int newfd, Comm::Connection *details,
+httpAccept(int sock, int newfd, Comm::Connection::Pointer details,
            comm_err_t flag, int xerrno, void *data)
 {
     http_port_list *s = (http_port_list *)data;
@@ -3120,7 +3120,7 @@ httpAccept(int sock, int newfd, Comm::Connection *details,
 
 /** Create SSL connection structure and update fd_table */
 static SSL *
-httpsCreate(int newfd, Comm::Connection *details, SSL_CTX *sslContext)
+httpsCreate(int newfd, Comm::Connection::Pointer details, SSL_CTX *sslContext)
 {
     SSL *ssl = SSL_new(sslContext);
 
@@ -3263,7 +3263,7 @@ clientNegotiateSSL(int fd, void *data)
 
 /** handle a new HTTPS connection */
 static void
-httpsAccept(int sock, int newfd, Comm::Connection *details,
+httpsAccept(int sock, int newfd, Comm::Connection::Pointer details,
             comm_err_t flag, int xerrno, void *data)
 {
     https_port_list *s = (https_port_list *)data;
index b34e36c5791e2999d80f7c2612e5ad388e964b07..2e9ebebce74ec89764b67416ad370881c6ebcf45 100644 (file)
@@ -793,43 +793,6 @@ comm_openex(int sock_type,
     return new_socket;
 }
 
-#if 0
-// AYJ: this API is dead. alter the caller which is using this to do its own DNS lookups
-//     and generate a Vector<Comm::Connection*> of possible destinations.
-//     do the rest of this itself...
-void
-commConnectStart(int fd, const char *host, u_short port, AsyncCall::Pointer &cb)
-{
-    debugs(cb->debugSection, cb->debugLevel, "commConnectStart: FD " << fd <<
-           ", cb " << cb << ", " << host << ":" << port); // TODO: just print *cb
-
-    ConnectStateData *cs;
-    cs = new ConnectStateData;
-    cs->fd = fd;
-    cs->host = xstrdup(host);
-    cs->default_port = port;
-    cs->callback = cb;
-
-    comm_add_close_handler(fd, ConnectStateData::Free, cs);
-    ipcache_nbgethostbyname(host, commConnectDnsHandle, cs);
-}
-#endif
-
-#if 0
-// TODO: Remove this and similar callback registration functions by replacing
-// (callback,data) parameters with an AsyncCall so that we do not have to use
-// a generic call name and debug level when creating an AsyncCall. This will
-// also cut the number of callback registration routines in half.
-void
-commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data)
-{
-    debugs(5, 5, "commConnectStart: FD " << fd << ", data " << data << ", " << host << ":" << port);
-    AsyncCall::Pointer call = commCbCall(5,3,
-                                         "SomeCommConnectHandler", CommConnectCbPtrFun(callback, data));
-    commConnectStart(fd, host, port, call);
-}
-#endif
-
 static void
 copyFDFlags(int to, fde *F)
 {
@@ -1188,7 +1151,7 @@ comm_close_complete(int fd, void *data)
  * Close the socket fd in use by a connection.
  */
 void
-_comm_close(Comm::Connection *conn, char const *file, int line)
+_comm_close(Comm::Connection::Pointer conn, char const *file, int line)
 {
     _comm_close(conn->fd, file, line);
     conn->fd = -1;
index ac63caf6e686346a9ec5c454d951c9173c5df2ac..2c452d55d337752440cdee45200fa36be1e83ae8 100644 (file)
@@ -13,7 +13,7 @@
 #define COMMIO_FD_READCB(fd)    (&commfd_table[(fd)].readcb)
 #define COMMIO_FD_WRITECB(fd)   (&commfd_table[(fd)].writecb)
 
-typedef void CNCB(Comm::Connection *conn, Vector<Comm::Connection*> *paths, comm_err_t status, int xerrno, void *data);
+typedef void CNCB(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *paths, comm_err_t status, int xerrno, void *data);
 typedef void IOCB(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data);
 
 
@@ -25,7 +25,7 @@ SQUIDCEXTERN int commUnsetNonBlocking(int fd);
 SQUIDCEXTERN void commSetCloseOnExec(int fd);
 SQUIDCEXTERN void commSetTcpKeepalive(int fd, int idle, int interval, int timeout);
 extern void _comm_close(int fd, char const *file, int line);
-extern void _comm_close(Comm::Connection *conn, char const *file, int line);
+extern void _comm_close(Comm::Connection::Pointer conn, char const *file, int line);
 #define comm_close(x) (_comm_close((x), __FILE__, __LINE__))
 SQUIDCEXTERN void comm_reset_close(int fd);
 #if LINGERING_CLOSE
@@ -85,7 +85,7 @@ SQUIDCEXTERN comm_err_t comm_select(int);
 SQUIDCEXTERN void comm_quick_poll_required(void);
 
 #include "comm/Connection.h"
-typedef void IOACB(int fd, int nfd, Comm::Connection *details, comm_err_t flag, int xerrno, void *data);
+typedef void IOACB(int fd, int nfd, Comm::Connection::Pointer details, comm_err_t flag, int xerrno, void *data);
 extern void comm_add_close_handler(int fd, PF *, void *);
 extern void comm_add_close_handler(int fd, AsyncCall::Pointer &);
 extern void comm_remove_close_handler(int fd, PF *, void *);
index 983f0f8493b250c6125fcd4d33f039677e362fa4..51c4248c0a05b41ee3a8c8cdc3423c33de1e17d6 100644 (file)
@@ -2,12 +2,13 @@
 #include "comm/ConnectStateData.h"
 #include "comm.h"
 #include "CommCalls.h"
+#include "fde.h"
 #include "icmp/net_db.h"
 #include "SquidTime.h"
 
 CBDATA_CLASS_INIT(ConnectStateData);
 
-ConnectStateData::ConnectStateData(Vector<Comm::Connection*> *paths, AsyncCall::Pointer handler) :
+ConnectStateData::ConnectStateData(Vector<Comm::Connection::Pointer> *paths, AsyncCall::Pointer handler) :
         host(NULL),
         connect_timeout(Config.Timeout.connect),
         paths(paths),
@@ -18,7 +19,7 @@ ConnectStateData::ConnectStateData(Vector<Comm::Connection*> *paths, AsyncCall::
         connstart(0)
 {}
 
-ConnectStateData::ConnectStateData(Comm::Connection *c, AsyncCall::Pointer handler) :
+ConnectStateData::ConnectStateData(Comm::Connection::Pointer c, AsyncCall::Pointer handler) :
         host(NULL),
         connect_timeout(Config.Timeout.connect),
         paths(paths),
@@ -76,7 +77,7 @@ ConnectStateData::callCallback(comm_err_t status, int xerrno)
 void
 ConnectStateData::connect()
 {
-    Comm::Connection *active;
+    Comm::Connection::Pointer active;
 
     /* handle connecting to one single path */
     /* mainly used by components other than forwarding */
@@ -84,10 +85,10 @@ ConnectStateData::connect()
     /* handle connecting to one of multiple paths */
     /* mainly used by forwarding */
 
-    if (solo) {
+    if (solo != NULL) {
         active = solo;
     } else if (paths) {
-        Vector<Comm::Connection*>::iterator i = paths->begin();
+        Vector<Comm::Connection::Pointer>::iterator i = paths->begin();
 
         if (connstart == 0) {
             connstart = squid_curtime;
@@ -131,15 +132,20 @@ ConnectStateData::connect()
     case COMM_OK:
         debugs(5, 5, HERE << "FD " << active->fd << ": COMM_OK - connected");
 
-    /*
-     * stats.conn_open is used to account for the number of
-     * connections that we have open to the peer, so we can limit
-     * based on the max-conn option.  We need to increment here,
-     * even if the connection may fail.
-     */
+        /*
+         * stats.conn_open is used to account for the number of
+         * connections that we have open to the peer, so we can limit
+         * based on the max-conn option.  We need to increment here,
+         * even if the connection may fail.
+         */
         if (active->_peer)
             active->_peer->stats.conn_open++;
 
+        /* TODO: remove this fd_table access. But old code still depends on fd_table flags to
+         *       indicate the state of a raw fd object being passed around.
+         */
+        fd_table[active->fd].flags.open = 1;
+
         ipcacheMarkGoodAddr(host, active->remote);
         callCallback(COMM_OK, 0);
         break;
index eece8d15f0417cfd84f4f5e27dcc4d1198856e7d..60585effb81a54798e1335028e4a8800ee1dc6b2 100644 (file)
@@ -17,9 +17,9 @@ class ConnectStateData
 {
 public:
     /** open first working of a set of connections */
-    ConnectStateData(Vector<Comm::Connection *> *paths, AsyncCall::Pointer handler);
+    ConnectStateData(Vector<Comm::Connection::Pointer> *paths, AsyncCall::Pointer handler);
     /** attempt to open one connection. */
-    ConnectStateData(Comm::Connection *, AsyncCall::Pointer handler);
+    ConnectStateData(Comm::Connection::Pointer, AsyncCall::Pointer handler);
 
     void *operator new(size_t);
     void operator delete(void *);
@@ -62,9 +62,9 @@ public:
     time_t connect_timeout;
 
 private:
-    Vector<Comm::Connection *> *paths;  ///< forwarding paths to be tried. front of the list is the current being opened.
-    Comm::Connection *solo;             ///< single connection currently being opened.
-    AsyncCall::Pointer callback;        ///< handler to be called on connection completion.
+    Vector<Comm::Connection::Pointer> *paths;  ///< forwarding paths to be tried. front of the list is the current being opened.
+    Comm::Connection::Pointer solo;            ///< single connection currently being opened.
+    AsyncCall::Pointer callback;               ///< handler to be called on connection completion.
 
     int total_tries;   ///< total number of connection attempts over all destinations so far.
     int fail_retries;  ///< number of retries current destination has been tried.
index 4b9600c76193e5456204ec6fda544b8a14876397..e35cbbe7dbe91b04b43be9200fbba7d3a9674a9c 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * DEBUG: section 5     Socket Functions
+ * AUTHOR: Amos Jeffries
  * AUTHOR: Robert Collins
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -30,6 +31,7 @@
  *
  *
  * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Copyright (c) 2010, Amos Jeffries <amosjeffries@squid-cache.org>
  */
 
 #ifndef _SQUIDCONNECTIONDETAIL_H_
@@ -37,6 +39,7 @@
 
 #include "hier_code.h"
 #include "ip/Address.h"
+#include "RefCount.h"
 
 class peer;
 
@@ -51,9 +54,11 @@ namespace Comm {
 #define COMM_TRANSPARENT        0x08
 #define COMM_DOBIND             0x10
 
-class Connection
+class Connection : public RefCountable
 {
 public:
+    typedef RefCount<Comm::Connection> Pointer;
+
     Connection();
     Connection(Connection &c);
     ~Connection();
index 75222b60c93867c7aeb5b9f8c3053666bd81c630..04a99cf474b8f56aac01e3a3bd4874bb8eb13bab 100644 (file)
@@ -186,7 +186,7 @@ Comm::ListenStateData::acceptNext()
 }
 
 void
-Comm::ListenStateData::notify(int newfd, comm_err_t errcode, int xerrno, Comm::Connection *connDetails)
+Comm::ListenStateData::notify(int newfd, comm_err_t errcode, int xerrno, Comm::Connection::Pointer connDetails)
 {
     // listener socket handlers just abandon the port with COMM_ERR_CLOSING
     // it should only happen when this object is deleted...
index d436adfc7d155538a348da9ee2aeb5b88141b440..a83f8e2ecef461ff03a922f01be1d42433358b74 100644 (file)
@@ -23,7 +23,7 @@ public:
 
     void subscribe(AsyncCall::Pointer &call);
     void acceptNext();
-    void notify(int newfd, comm_err_t, int xerrno, Comm::Connection *);
+    void notify(int newfd, comm_err_t, int xerrno, Comm::Connection::Pointer);
 
     int fd;
 
index 8ac8cdd9d182ed52040f41b9b284e75609953574..c963c88fa5930026457cce7bbcc5b9bc90ef6420 100644 (file)
@@ -699,14 +699,14 @@ idnsDoSendQueryVC(nsvc *vc)
 }
 
 static void
-idnsInitVCConnected(Comm::Connection *conn, Vector<Comm::Connection *> *unused, comm_err_t status, int xerrno, void *data)
+idnsInitVCConnected(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *unused, comm_err_t status, int xerrno, void *data)
 {
     nsvc * vc = (nsvc *)data;
 
     if (status != COMM_OK || !conn) {
         char buf[MAX_IPSTRLEN];
         debugs(78, DBG_IMPORTANT, "Failed to connect to nameserver " << nameservers[vc->ns].S.NtoA(buf,MAX_IPSTRLEN) << " using TCP!");
-        delete conn;
+        conn = NULL;
         return;
     }
 
@@ -731,8 +731,6 @@ idnsVCClosed(int fd, void *data)
 static void
 idnsInitVC(int ns)
 {
-    char buf[MAX_IPSTRLEN];
-
     nsvc *vc = cbdataAlloc(nsvc);
     nameservers[ns].vc = vc;
     vc->ns = ns;
@@ -740,7 +738,7 @@ idnsInitVC(int ns)
     vc->msg = new MemBuf;
     vc->busy = 1;
 
-    Comm::Connection *conn = new Comm::Connection;
+    Comm::Connection::Pointer conn = new Comm::Connection;
 
     if (!Config.Addrs.udp_outgoing.IsNoAddr())
         conn->local = Config.Addrs.udp_outgoing;
index ffa621c9bafbbe3845cf214e9012265ad87d3124..3ddd618ba35084786aa0670311921fda98a8ea5c 100644 (file)
@@ -360,7 +360,7 @@ FwdState::complete()
 /**** CALLBACK WRAPPERS ************************************************************/
 
 static void
-fwdStartCompleteWrapper(Vector<Comm::Connection*> *unused, void *data)
+fwdStartCompleteWrapper(Vector<Comm::Connection::Pointer> *unused, void *data)
 {
     FwdState *fwd = (FwdState *) data;
     fwd->startComplete();
@@ -390,7 +390,7 @@ fwdNegotiateSSLWrapper(int fd, void *data)
 #endif
 
 void
-fwdConnectDoneWrapper(Comm::Connection *conn, Vector<Comm::Connection*> *paths, comm_err_t status, int xerrno, void *data)
+fwdConnectDoneWrapper(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *paths, comm_err_t status, int xerrno, void *data)
 {
     FwdState *fwd = (FwdState *) data;
     fwd->connectDone(conn, paths, status, xerrno);
@@ -663,7 +663,7 @@ FwdState::initiateSSL()
 #endif
 
 void
-FwdState::connectDone(Comm::Connection *conn, Vector<Comm::Connection*> *result_paths, comm_err_t status, int xerrno)
+FwdState::connectDone(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *result_paths, comm_err_t status, int xerrno)
 {
     assert(result_paths == &paths);
 
@@ -740,7 +740,7 @@ FwdState::connectStart()
     if (n_tries == 0) // first attempt
         request->hier.first_conn_start = current_time;
 
-    Comm::Connection *conn = paths[0];
+    Comm::Connection::Pointer conn = paths[0];
 
     /* connection timeout */
     int ctimeout;
@@ -781,7 +781,7 @@ FwdState::connectStart()
         debugs(17,2,HERE << " Pinned connection " << pinned_connection << " not valid. Releasing.");
         request->releasePinnedConnection();
         paths.shift();
-        delete conn;
+        conn = NULL;
         connectStart();
         return;
     }
@@ -789,7 +789,8 @@ FwdState::connectStart()
 // TODO: now that we are dealing with actual IP->IP links. should we still anchor pconn on hostname?
 //     or on the remote IP+port?
 // that could reduce the pconns per virtual server a fair amount
-// and prevent crossover between servers hosting the one domain
+// but would prevent crossover between servers hosting the one domain
+// this currently opens the possibility that conn will lie about where the FD goes.
 
     const char *host;
     int port;
@@ -831,18 +832,6 @@ FwdState::connectStart()
     cs->connect();
 }
 
-#if DEAD
-void
-FwdState::startFail()
-{
-    debugs(17, 3, HERE << entry->url()  );
-    ErrorState *anErr = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE, request);
-    anErr->xerrno = errno;
-    fail(anErr);
-    self = NULL;       // refcounted
-}
-#endif
-
 void
 FwdState::dispatch()
 {
@@ -1086,15 +1075,21 @@ FwdState::reforwardableStatus(http_status s)
  *  -  address of the client for which we made the connection
  */
 void
-FwdState::pconnPush(int fd, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr)
+FwdState::pconnPush(Comm::Connection::Pointer conn, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr)
 {
     if (_peer) {
-        fwdPconnPool->push(fd, _peer->name, _peer->http_port, domain, client_addr);
+        fwdPconnPool->push(conn->fd, _peer->name, _peer->http_port, domain, client_addr);
     } else {
         /* small performance improvement, using NULL for domain instead of listing it twice */
         /* although this will leave a gap open for url-rewritten domains to share a link */
-        fwdPconnPool->push(fd, req->GetHost(), req->port, NULL, client_addr);
+        fwdPconnPool->push(conn->fd, req->GetHost(), req->port, NULL, client_addr);
     }
+
+    /* XXX: remove this when Comm::Connection are stored in the pool
+     * this only prevents the persistent FD being closed when the
+     * Comm::Connection currently using it is destroyed.
+     */
+    conn->fd = -1;
 }
 
 void
@@ -1175,24 +1170,6 @@ FwdState::updateHierarchyInfo()
 
 /**** PRIVATE NON-MEMBER FUNCTIONS ********************************************/
 
-#if DEAD
-static Ip::Address
-aclMapAddr(acl_address * head, ACLChecklist * ch)
-{
-    acl_address *l;
-
-    Ip::Address addr;
-
-    for (l = head; l; l = l->next) {
-        if (!l->aclList || ch->matchAclListFast(l->aclList))
-            return l->addr;
-    }
-
-    addr.SetAnyAddr();
-    return addr;
-}
-#endif
-
 /*
  * DPW 2007-05-19
  * Formerly static, but now used by client_side_request.cc
@@ -1211,7 +1188,7 @@ aclMapTOS(acl_tos * head, ACLChecklist * ch)
 }
 
 void
-getOutgoingAddress(HttpRequest * request, Comm::Connection *conn)
+getOutgoingAddress(HttpRequest * request, Comm::Connection::Pointer conn)
 {
     /* skip if an outgoing address is already set. */
     if (!conn->local.IsAnyAddr()) return;
index 804b239e900ca59518a10af33f78b187646b2a3f..a5e30a3a2bcb7a1069890d9d072bd7b0092ca28e 100644 (file)
@@ -8,23 +8,9 @@ class HttpRequest;
 
 #include "comm.h"
 #include "comm/Connection.h"
-//#include "hier_code.h"
 #include "ip/Address.h"
 #include "Array.h"
 
-#if 0 // replaced by vector of extended Comm::Connection objects (paths)
-class FwdServer
-{
-public:
-    peer *_peer;                /* NULL --> origin server */
-    hier_code code;
-    FwdServer *next;
-};
-
-typedef void PSC(FwdServer *, void *);
-
-#endif
-
 class FwdState : public RefCountable
 {
 public:
@@ -34,7 +20,6 @@ public:
 
     static void fwdStart(int fd, StoreEntry *, HttpRequest *);
     void startComplete();
-//    void startFail();
     void fail(ErrorState *err);
     void unregister(int fd);
     void complete();
@@ -43,14 +28,14 @@ public:
     bool reforwardableStatus(http_status s);
     void serverClosed(int fd);
     void connectStart();
-    void connectDone(Comm::Connection *conn, Vector<Comm::Connection*> *paths, comm_err_t status, int xerrno);
+    void connectDone(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *paths, comm_err_t status, int xerrno);
     void connectTimeout(int fd);
     void initiateSSL();
     void negotiateSSL(int fd);
     bool checkRetry();
     bool checkRetriable();
     void dispatch();
-    void pconnPush(int fd, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr);
+    void pconnPush(Comm::Connection::Pointer conn, const peer *_peer, const HttpRequest *req, const char *domain, Ip::Address &client_addr);
 
     bool dontRetry() { return flags.dont_retry; }
 
@@ -60,7 +45,7 @@ public:
 
     void ftpPasvFailed(bool val) { flags.ftp_pasv_failed = val; }
 
-    Comm::Connection *conn() const { return paths[0]; };
+    Comm::Connection::Pointer conn() const { return paths[0]; };
 
 private:
     // hidden for safer management of self; use static fwdStart
@@ -104,7 +89,7 @@ private:
     } flags;
 
     /** possible paths which may be tried (in sequence stored) */
-    Vector<Comm::Connection*> paths;
+    Vector<Comm::Connection::Pointer> paths;
 
     // NP: keep this last. It plays with private/public
     CBDATA_CLASS2(FwdState);
index 1f3dea861d61133986aede24e20d6bf1d5b3d4bc..a6c4a23cb2da3f5c78c2d942dfa8911c1cc13970 100644 (file)
@@ -2406,7 +2406,7 @@ ftpReadEPSV(FtpStateData* ftpState)
 
     debugs(9, 3, HERE << "connecting to " << ftpState->data.host << ", port " << ftpState->data.port);
 
-    Comm::Connection *conn = new Comm::Connection;
+    Comm::Connection::Pointer conn = new Comm::Connection;
     conn->remote = fd_table[ftpState->ctrl.fd].ipaddr; // TODO: do we have a better info source than fd_table?
     conn->remote.SetPort(port);
     conn->fd = fd;
@@ -2691,7 +2691,7 @@ ftpReadPasv(FtpStateData * ftpState)
 
     debugs(9, 3, HERE << "connecting to " << ftpState->data.host << ", port " << ftpState->data.port);
 
-    Comm::Connection *conn = new Comm::Connection;
+    Comm::Connection::Pointer conn = new Comm::Connection;
     conn->remote = ipaddr;
     conn->remote.SetPort(port);
     conn->fd = ftpState->data.fd;
@@ -2704,7 +2704,7 @@ ftpReadPasv(FtpStateData * ftpState)
 }
 
 void
-FtpStateData::ftpPasvCallback(Comm::Connection *conn, Vector<Comm::Connection*> *unused, comm_err_t status, int xerrno, void *data)
+FtpStateData::ftpPasvCallback(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *unused, comm_err_t status, int xerrno, void *data)
 {
     FtpStateData *ftpState = (FtpStateData *)data;
     debugs(9, 3, HERE);
index 40123f58aa84ae0620f25379869c21292cde4e48..8079befae14e1631b736c71ed3d0bb02d7900ffb 100644 (file)
@@ -95,7 +95,7 @@ HttpStateData::HttpStateData(FwdState *theFwdState) : AsyncJob("HttpStateData"),
     orig_request->hier.peer_http_request_sent.tv_sec = 0;
     orig_request->hier.peer_http_request_sent.tv_usec = 0;
 
-    if (fwd->conn())
+    if (fwd->conn() != NULL)
         _peer = fwd->conn()->_peer;         /* might be NULL */
 
     if (_peer) {
@@ -1368,7 +1368,7 @@ HttpStateData::processReplyBody()
                 orig_request->pinnedConnection()->pinConnection(fd, orig_request, _peer,
                         (request->flags.connection_auth != 0));
             } else {
-                fwd->pconnPush(fd, _peer, request, orig_request->GetHost(), client_addr);
+                fwd->pconnPush(fwd->conn(), _peer, request, orig_request->GetHost(), client_addr);
             }
 
             fd = -1;
index a34990a9a04118f766adf15696bdf9efd3a37764..7a5e959c05417ad5726fe2af9d00e4d1197fd1f2 100644 (file)
@@ -117,7 +117,7 @@ Ident::Timeout(int fd, void *data)
 }
 
 void
-Ident::ConnectDone(Comm::Connection *conn, Vector<Comm::Connection*> *unused, comm_err_t status, int xerrno, void *data)
+Ident::ConnectDone(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *unused, comm_err_t status, int xerrno, void *data)
 {
     IdentStateData *state = (IdentStateData *)data;
 
@@ -217,7 +217,7 @@ CBDATA_TYPE(IdentStateData);
  * start a TCP connection to the peer host on port 113
  */
 void
-Ident::Start(Comm::Connection *conn, IDCB * callback, void *data)
+Ident::Start(Comm::Connection::Pointer conn, IDCB * callback, void *data)
 {
     IdentStateData *state;
     char key1[IDENT_KEY_SZ];
index b7cbb9f34bda9f87d9e50d13afb8ec60a2a02b14..84124ed2e06dfa12c5ea05064426309af97b00e5 100644 (file)
@@ -27,7 +27,7 @@ namespace Ident
  * Self-registers with a global ident lookup manager,
  * will call Ident::Init() itself if the manager has not been initialized already.
  */
-void Start(Comm::Connection *conn, IDCB * callback, void *cbdata);
+void Start(Comm::Connection::Pointer conn, IDCB * callback, void *cbdata);
 
 /**
  \ingroup IdentAPI
index b7d9aafb014cf43382ec0064cf03fbedd3261f08..532719139f873efd4a3d2b7b0a411809fbdfea83 100644 (file)
@@ -1359,9 +1359,9 @@ peerProbeConnect(peer * p)
         return ret;/* don't probe to often */
 
     /* for each IP address of this peer. find one that we can connect to and probe it. */
-    Vector<Comm::Connection *> *paths = new Vector<Comm::Connection *>;
+    Vector<Comm::Connection::Pointer> *paths = new Vector<Comm::Connection::Pointer>;
     for (int i = 0; i < p->n_addresses; i++) {
-        Comm::Connection *conn = new Comm::Connection;
+        Comm::Connection::Pointer conn = new Comm::Connection;
         conn->remote = p->addresses[i];
         conn->remote.SetPort(p->http_port);
         getOutgoingAddress(NULL, conn);
@@ -1381,7 +1381,7 @@ peerProbeConnect(peer * p)
 }
 
 static void
-peerProbeConnectDone(Comm::Connection *conn, Vector<Comm::Connection*> *unused, comm_err_t status, int xerrno, void *data)
+peerProbeConnectDone(Comm::Connection::Pointer conn, Vector<Comm::Connection::Pointer> *unused, comm_err_t status, int xerrno, void *data)
 {
     peer *p = (peer*)data;
 
index f01777322233324c8af2a19ef4ea90ca30ebad0c..b51ff16f755510536c55c0df50cd637b214062e9 100644 (file)
@@ -124,7 +124,7 @@ peerSelectIcpPing(HttpRequest * request, int direct, StoreEntry * entry)
 
 
 void
-peerSelect(Vector<Comm::Connection*> *paths,
+peerSelect(Vector<Comm::Connection::Pointer> *paths,
            HttpRequest * request,
            StoreEntry * entry,
            PSC * callback,
@@ -253,7 +253,7 @@ peerSelectDnsResults(const ipcache_addrs *ia, const DnsLookupDetails &details, v
         assert(ia->cur < ia->count);
 
         // loop over each result address, adding to the possible destinations.
-        Comm::Connection *p;
+        Comm::Connection::Pointer p;
         int ip = ia->cur;
         for (int n = 0; n < ia->count; n++, ip++) {
             if (ip >= ia->count) ip = 0; // looped back to zero.
index 6975f2cc29b692f5930052d63f82e691a3e418ea..24c24677dd21b32af2c099285c6824dce7e2108f 100644 (file)
@@ -406,7 +406,7 @@ SQUIDCEXTERN void peerDigestNotePeerGone(PeerDigest * pd);
 SQUIDCEXTERN void peerDigestStatsReport(const PeerDigest * pd, StoreEntry * e);
 
 #include "comm/Connection.h"
-extern void getOutgoingAddress(HttpRequest * request, Comm::Connection *conn);
+extern void getOutgoingAddress(HttpRequest * request, Comm::Connection::Pointer conn);
 unsigned long getOutgoingTOS(HttpRequest * request);
 
 SQUIDCEXTERN void urnStart(HttpRequest *, StoreEntry *);
index e945eb785e0e444657fdc4d7a6af167b00b9daac..3ac26e6ec99fa7c93139f799ce9ee265d7e4abbe 100644 (file)
@@ -68,7 +68,7 @@ public:
     char *host;                        /* either request->host or proxy host */
     u_short port;
     HttpRequest *request;
-    Vector<Comm::Connection*> *paths;
+    Vector<Comm::Connection::Pointer> *paths;
 
     class Connection
     {
@@ -558,12 +558,12 @@ tunnelErrorComplete(int fdnotused, void *data, size_t sizenotused)
 
 
 static void
-tunnelConnectDone(Comm::Connection *unused, Vector<Comm::Connection*> *paths, comm_err_t status, int xerrno, void *data)
+tunnelConnectDone(Comm::Connection::Pointer unused, Vector<Comm::Connection::Pointer> *paths, comm_err_t status, int xerrno, void *data)
 {
     TunnelStateData *tunnelState = (TunnelStateData *)data;
     HttpRequest *request = tunnelState->request;
     ErrorState *err = NULL;
-    Comm::Connection *conn = (*paths)[0];
+    Comm::Connection::Pointer conn = (*paths)[0];
 
     assert(tunnelState->paths == paths);
 
@@ -713,7 +713,7 @@ tunnelProxyConnected(int fd, void *data)
 }
 
 static void
-tunnelPeerSelectComplete(Vector<Comm::Connection*> *peer_paths, void *data)
+tunnelPeerSelectComplete(Vector<Comm::Connection::Pointer> *peer_paths, void *data)
 {
     TunnelStateData *tunnelState = (TunnelStateData *)data;
     HttpRequest *request = tunnelState->request;