From 2dfede9e81b81addee5524cfb113d30da694687d Mon Sep 17 00:00:00 2001 From: wessels <> Date: Sat, 3 Dec 2005 02:43:38 +0000 Subject: [PATCH] Some additions and changes for ICAP server connection reuse. --- src/ICAP/ICAPConfig.cc | 6 +++--- src/ICAP/ICAPModXact.cc | 7 ++++++- src/ICAP/ICAPXaction.cc | 36 +++++++++++++++++++++++++++++++++++- src/ICAP/ICAPXaction.h | 5 ++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/ICAP/ICAPConfig.cc b/src/ICAP/ICAPConfig.cc index 6925f02975..ec4f6336b7 100644 --- a/src/ICAP/ICAPConfig.cc +++ b/src/ICAP/ICAPConfig.cc @@ -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(); diff --git a/src/ICAP/ICAPModXact.cc b/src/ICAP/ICAPModXact.cc index b36156401d..e4dd01a579 100644 --- a/src/ICAP/ICAPModXact.cc +++ b/src/ICAP/ICAPModXact.cc @@ -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 diff --git a/src/ICAP/ICAPXaction.cc b/src/ICAP/ICAPXaction.cc index b980ccad9c..b4bb330c84 100644 --- a/src/ICAP/ICAPXaction.cc +++ b/src/ICAP/ICAPXaction.cc @@ -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; diff --git a/src/ICAP/ICAPXaction.h b/src/ICAP/ICAPXaction.h index b90f48a5aa..5215b93750 100644 --- a/src/ICAP/ICAPXaction.h +++ b/src/ICAP/ICAPXaction.h @@ -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); }; -- 2.47.3