]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make conn a shared field for CommCalls
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 4 Sep 2010 15:03:12 +0000 (03:03 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 4 Sep 2010 15:03:12 +0000 (03:03 +1200)
Create a commSetConnTimeout() function to hide FD field from code
needing to set timeouts.

Also, some extra build fixes after FwdStart and server Start() changes.

src/CommCalls.cc
src/CommCalls.h
src/client_side_reply.cc
src/comm.cc
src/comm.h
src/icmp/net_db.cc
src/peer_digest.cc
src/tests/stub_cache_manager.cc

index 63d51750fbaf8b27e4b443bea88a4f301107a3b0..fd5a14a5995557f755ce684f3251fc5f07f77258 100644 (file)
@@ -23,7 +23,11 @@ CommCommonCbParams::~CommCommonCbParams()
 void
 CommCommonCbParams::print(std::ostream &os) const
 {
-    os << "FD " << fd;
+    if (conn != NULL)
+        os << conn;
+    else
+        os << "FD " << fd;
+
     if (xerrno)
         os << ", errno=" << xerrno;
     if (flag != COMM_OK)
@@ -70,14 +74,6 @@ CommConnectCbParams::syncWithComm()
     return true; // now we are in sync and can handle the call
 }
 
-void
-CommConnectCbParams::print(std::ostream &os) const
-{
-    CommCommonCbParams::print(os);
-    if (conn != NULL)
-        os << ", " << conn;
-}
-
 /* CommIoCbParams */
 
 CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
@@ -124,7 +120,6 @@ CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
 {
 }
 
-
 /* CommAcceptCbPtrFun */
 
 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
@@ -231,6 +226,16 @@ CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler,
 void
 CommTimeoutCbPtrFun::dial()
 {
+    // AYJ NP: since the old code is still used by pipes and IPC
+    // we cant discard the params.fd functions entirely for old callbacks.
+    // new callers supposed to only set conn.
+    // sync FD and conn fields at this single failure point before dialing.
+    if (params.conn != NULL) {
+        if (params.fd < 0 && params.conn->fd > 0)
+            params.fd = params.conn->fd;
+        assert(params.fd == params.conn->fd); // Must() ?
+    }
+
     handler(params.fd, params.data);
 }
 
index b67b59b2cb645bba15ef92b0c9bf2dd9170b98b2..cff7d5a5ad50d033067d973a2295a59226463f29 100644 (file)
@@ -54,7 +54,8 @@ public:
 
 public:
     void *data; // cbdata-protected
-    int fd;
+    Comm::ConnectionPointer conn;
+    int fd; // raw FD from legacy calls. use conn instead.
     int xerrno;
     comm_err_t flag;
 
@@ -83,11 +84,6 @@ public:
     CommConnectCbParams(void *aData);
 
     bool syncWithComm(); // see CommCommonCbParams::syncWithComm
-
-    void print(std::ostream &os) const;
-
-public:
-    Comm::ConnectionPointer conn;
 };
 
 // read/write (I/O) parameters
index 67626523f3524f5df54972806c80e78e7385d185..75bad3daff803a4018e6bc3a3ab0d75c849a287a 100644 (file)
@@ -1683,7 +1683,7 @@ clientReplyContext::doGetMoreData()
 #if USE_ZPH_QOS
         if (Ip::Qos::TheConfig.tos_local_hit) {
             debugs(33, 2, "ZPH Local hit, TOS=" << Ip::Qos::TheConfig.tos_local_hit);
-            comm_set_tos(http->getConn()->fd, Ip::Qos::TheConfig.tos_local_hit);
+            comm_set_tos(http->getConn()->clientConn->fd, Ip::Qos::TheConfig.tos_local_hit);
         }
 #endif /* USE_ZPH_QOS */
         localTempBuffer.offset = reqofs;
index 6ba1ab62b680e7f86831ca55c12768299fa151bb..d3f17c5825e97bd263da99542fa979380272688d 100644 (file)
@@ -876,6 +876,7 @@ commSetTimeout_old(int fd, int timeout, PF * handler, void *data)
 }
 #endif
 
+// Legacy pre-AsyncCalls API for FD timeouts.
 int
 commSetTimeout(int fd, int timeout, PF * handler, void *data)
 {
@@ -888,7 +889,8 @@ commSetTimeout(int fd, int timeout, PF * handler, void *data)
     return commSetTimeout(fd, timeout, call);
 }
 
-
+// Legacy pre-Comm::Connection API for FD timeouts
+// still used by non-socket FD code dealing with pipes and IPC sockets.
 int
 commSetTimeout(int fd, int timeout, AsyncCall::Pointer &callback)
 {
@@ -913,7 +915,32 @@ commSetTimeout(int fd, int timeout, AsyncCall::Pointer &callback)
     }
 
     return F->timeout;
+}
+
+int
+commSetConnTimeout(const Comm::ConnectionPointer &conn, int timeout, AsyncCall::Pointer &callback)
+{
+    debugs(5, 3, HERE << conn << " timeout " << timeout);
+    assert(Comm::IsConnOpen(conn));
+    assert(conn->fd < Squid_MaxFD);
+    fde *F = &fd_table[conn->fd];
+    assert(F->flags.open);
+
+    if (timeout < 0) {
+        F->timeoutHandler = NULL;
+        F->timeout = 0;
+    } else {
+        if (callback != NULL) {
+            typedef CommTimeoutCbParams Params;
+            Params &params = GetCommParams<Params>(callback);
+            params.conn = conn;
+            F->timeoutHandler = callback;
+        }
 
+        F->timeout = squid_curtime + (time_t) timeout;
+    }
+
+    return F->timeout;
 }
 
 int
index fdcd4df84133f39988592475f055703638d53061..6caf48aa6bcaff084c7dde71d967611253830126 100644 (file)
@@ -70,6 +70,13 @@ extern void comm_write_mbuf(int fd, MemBuf *mb, AsyncCall::Pointer &callback);
 SQUIDCEXTERN void commCallCloseHandlers(int fd);
 SQUIDCEXTERN int commSetTimeout(int fd, int, PF *, void *);
 extern int commSetTimeout(int fd, int, AsyncCall::Pointer &calback);
+
+/**
+ * Set or clear the timeout for some action on an active connection.
+ * API to replace commSetTimeout() when a Comm::ConnectionPointer is available.
+ */
+extern int commSetConnTimeout(const Comm::ConnectionPointer &conn, int seconds, AsyncCall::Pointer &calback);
+
 SQUIDCEXTERN int ignoreErrno(int);
 SQUIDCEXTERN void commCloseAllSockets(void);
 SQUIDCEXTERN void checkTimeouts(void);
index 58532b5c01521b3a943358f6f35c85c9aadf2a6e..359e584ac0fd9012ba3c15582d06ee62080d0a66 100644 (file)
@@ -1336,7 +1336,8 @@ netdbExchangeStart(void *data)
 
     urlCanonical(ex->r);
 
-    FwdState::fwdStart(-1, ex->e, ex->r);
+    Comm::ConnectionPointer nul;
+    FwdState::fwdStart(nul, ex->e, ex->r);
 
 #endif
 }
index 4f009ec93e592296c73dadd1388a13cf9d1154c4..e8cb71d8915513b64cdf0f91426306b904921f5f 100644 (file)
@@ -393,7 +393,8 @@ peerDigestRequest(PeerDigest * pd)
     /* push towards peer cache */
     debugs(72, 3, "peerDigestRequest: forwarding to fwdStart...");
 
-    FwdState::fwdStart(-1, e, req);
+    Comm::ConnectionPointer nul;
+    FwdState::fwdStart(nul, e, req);
 
     tempBuffer.offset = 0;
 
index b67584e549a5ce70dc8542cda77cc4cc29fad3ff..bb2bb8085d625b3f2f4dd7385388d7d66b2deedc 100644 (file)
@@ -57,7 +57,7 @@ CacheManager::findAction(char const * action)
 }
 
 void
-CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry)
+CacheManager::Start(const Comm::ConnectionPointer &conn, HttpRequest * request, StoreEntry * entry)
 {
     return;
 }