]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Some additions and changes for ICAP server connection reuse.
authorwessels <>
Sat, 3 Dec 2005 02:43:38 +0000 (02:43 +0000)
committerwessels <>
Sat, 3 Dec 2005 02:43:38 +0000 (02:43 +0000)
src/ICAP/ICAPConfig.cc
src/ICAP/ICAPModXact.cc
src/ICAP/ICAPXaction.cc
src/ICAP/ICAPXaction.h

index 6925f02975c91c4f669d1d9342519e3ff31ee027..ec4f6336b75dc70ce97220b2874a5022d2bd44bc 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ICAPConfig.cc,v 1.3 2005/12/01 22:39:46 wessels Exp $
+ * $Id: ICAPConfig.cc,v 1.4 2005/12/02 19:43:38 wessels Exp $
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
  * ----------------------------------------------------------
@@ -155,7 +155,7 @@ ICAPAccessCheck::check()
             if (point != theService->point)
                 continue;
 
-            debug(93,1)("ICAPAccessCheck::check: class '%s' has candidate service '%s'\n", theClass->key.buf(), theService->key.buf());
+            debug(93,3)("ICAPAccessCheck::check: class '%s' has candidate service '%s'\n", theClass->key.buf(), theService->key.buf());
 
             candidateClasses += theClass->key;
 
@@ -197,7 +197,7 @@ ICAPAccessCheck::checkCandidates()
      * when there are no canidates, set matchedClass to NULL string
      * and call the wrapper with answer = 1
      */
-    debug(93,1)("ICAPAccessCheck::check: NO candidates or matches found\n");
+    debug(93,3)("ICAPAccessCheck::check: NO candidates or matches found\n");
 
     matchedClass.clean();
 
index b36156401dee92e69f83bfda20ff3021c6be4e7d..e4dd01a5791e7989dd5595d6dc64e23c9fdcb350 100644 (file)
@@ -706,6 +706,11 @@ bool ICAPModXact::parseHead(HttpMsg *head)
         return false;
     }
 
+    if (httpHeaderHasConnDir(&head->header, "close")) {
+        debug(0,0)("%s(%d) found connection close!\n", __FILE__,__LINE__);
+        reuseConnection = false;
+    }
+
     readBuf.consume(head->hdr_sz);
     return true;
 }
@@ -937,7 +942,7 @@ void ICAPModXact::makeRequestHeaders(MemBuf &buf)
             if (request->auth_user_request->username())
                 buf.Printf("X-Client-Username: %s\r\n", request->auth_user_request->username());
 
-    fprintf(stderr, "%s\n", buf.content());
+    // fprintf(stderr, "%s\n", buf.content());
 
     buf.append(ICAP::crlf, 2); // terminate ICAP header
 
index b980ccad9c642f020625f811fb965944ed516ed8..b4bb330c8495f50ea0ca47edc97b0846e16acae1 100644 (file)
@@ -57,6 +57,7 @@ ICAPXaction::ICAPXaction(const char *aTypeName):
         connection(-1),
         commBuf(NULL), commBufSize(0),
         commEof(false),
+        reuseConnection(true),
         connector(NULL), reader(NULL), writer(NULL), closer(NULL),
         typeName(aTypeName),
         theService(NULL),
@@ -82,6 +83,17 @@ void ICAPXaction::openConnection()
     // TODO: check whether NULL domain is appropriate here
     connection = pconnPop(s.host.buf(), s.port, NULL);
 
+    if (connection >= 0) {
+        debug(93,3)("%s(%d) reused pconn FD %d\n", __FILE__, __LINE__, connection);
+        eventAdd("ICAPXaction::reusedConnection",
+                 reusedConnection,
+                 this,
+                 0.0,
+                 0,
+                 true);
+        return;
+    }
+
     if (connection < 0) {
         connection = comm_open(SOCK_STREAM, 0, getOutgoingAddr(NULL), 0,
                                COMM_NONBLOCKING, s.uri.buf());
@@ -102,6 +114,22 @@ void ICAPXaction::openConnection()
     commConnectStart(connection, s.host.buf(), s.port, connector, this);
 }
 
+/*
+ * This event handler is necessary to work around the no-rentry policy
+ * of ICAPXaction::callStart()
+ */
+void
+ICAPXaction::reusedConnection(void *data)
+{
+    debug(93,5)("ICAPXaction::reusedConnection\n");
+    ICAPXaction *x = (ICAPXaction*)data;
+    /*
+     * XXX noteCommConnected Must()s that connector is set to something;
+     */
+    x->connector = &ICAPXaction_noteCommConnected;
+    x->noteCommConnected(COMM_OK);
+}
+
 void ICAPXaction::closeConnection()
 {
     if (connection >= 0) {
@@ -114,7 +142,13 @@ void ICAPXaction::closeConnection()
 
         cancelRead();
 
-        comm_close(connection);
+        if (reuseConnection) {
+            debug(93,3)("%s(%d) pushing pconn %d\n", __FILE__,__LINE__,connection);
+            pconnPush(connection, theService->host.buf(), theService->port, NULL);
+        } else {
+            debug(93,3)("%s(%d) closing pconn %d\n", __FILE__,__LINE__,connection);
+            comm_close(connection);
+        }
 
         connector = NULL;
         connection = -1;
index b90f48a5aa6119509cb8de6a6bf9f2b038949530..5215b93750b038f0957a9ce3c35df3ea8f4d75d5 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ICAPXaction.h,v 1.2 2005/11/21 23:46:27 wessels Exp $
+ * $Id: ICAPXaction.h,v 1.3 2005/12/02 19:43:38 wessels Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -115,6 +115,7 @@ protected:
     char *commBuf;
     size_t commBufSize;
     bool commEof;
+    bool reuseConnection;
 
     const char *stopReason;
 
@@ -136,6 +137,8 @@ private:
 
     const char *inCall; // name of the asynchronous call being executed, if any
 
+    static void ICAPXaction::reusedConnection(void *data);
+
     //CBDATA_CLASS2(ICAPXaction);
 };