--------------------- PatchSet 1536 Date: 2005/08/19 22:57:41 Author: dwsquid Branch: squid3-icap Tag: (none) Log: created a transactionComplete() method because there were too many places to worry about freeing state, unregistering handlers, and closing descriptors with ICAP. Members: src/http.cc:1.49.2.4->1.49.2.5 src/http.h:1.11.4.3->1.11.4.4 Index: squid3/src/http.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.cc,v retrieving revision 1.49.2.4 retrieving revision 1.49.2.5 diff -u -r1.49.2.4 -r1.49.2.5 --- squid3/src/http.cc 19 Aug 2005 21:58:38 -0000 1.49.2.4 +++ squid3/src/http.cc 19 Aug 2005 22:57:41 -0000 1.49.2.5 @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.49.2.4 2005/08/19 21:58:38 dwsquid Exp $ + * $Id: http.cc,v 1.49.2.5 2005/08/19 22:57:41 dwsquid Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -107,6 +107,7 @@ httpState->orig_request = NULL; #if ICAP_CLIENT cbdataReferenceDone(httpState->icap); + delete httpState->icap; #endif cbdataFree(httpState); } @@ -642,8 +643,7 @@ storeEntryReplaceObject (entry, reply); if (eof == 1) { - fwdComplete(fwd); - comm_close(fd); + transactionComplete(); } } @@ -784,8 +784,7 @@ #endif if (eof == 1) { - fwdComplete(fwd); - comm_close(fd); + transactionComplete(); } ctx_exit(ctx); } @@ -1086,15 +1085,11 @@ err->request = requestLink((HttpRequest *) request); fwdFail(fwd, err); fwd->flags.dont_retry = 1; + flags.do_next_read = 0; + comm_close(fd); } else { -#if ICAP_CLIENT - icap->doneSending(); -#endif - fwdComplete(fwd); + transactionComplete(); } - - flags.do_next_read = 0; - comm_close(fd); } } else { if (!flags.headers_parsed) { @@ -1201,10 +1196,8 @@ /* yes we have to clear all these! */ commSetTimeout(fd, -1, NULL, NULL); flags.do_next_read = 0; - comm_remove_close_handler(fd, httpStateFree, this); fwdUnregister(fd, fwd); - if (_peer) { if (_peer->options.originserver) pconnPush(fd, _peer->name, orig_request->port, orig_request->host); @@ -1213,18 +1206,15 @@ } else { pconnPush(fd, request->host, request->port, NULL); } + fd = -1; - -#if ICAP_CLIENT - icap->doneSending(); -#endif - fwdComplete(fwd); - fd = -1; - httpStateFree(fd, this); + transactionComplete(); return; case COMPLETE_NONPERSISTENT_MSG: debug(0,0)("processReplyData: COMPLETE_NONPERSISTENT_MSG\n"); + +#if REALLY /* close the connection ourselves */ /* yes - same as for a complete persistent conn here */ commSetTimeout(fd, -1, NULL, NULL); @@ -1239,6 +1229,8 @@ comm_close (fd); fd = -1; httpStateFree(fd, this); +#endif + transactionComplete(); return; } @@ -1312,6 +1304,30 @@ } /* + * Calling this function marks the end of the HTTP transaction. + * i.e., done talking to the HTTP server. With ICAP, however, that + * does not mean that we're done with HttpStateData and the StoreEntry. + * We'll be expecting adapted data to come back from the ICAP + * routines. + */ +void +HttpStateData::transactionComplete() +{ + if (fd >= 0) { + fwdUnregister(fd, fwd); + comm_remove_close_handler(fd, httpStateFree, this); + comm_close(fd); + fd = -1; + } +#if ICAP_CLIENT + icap->doneSending(); +#else + fwdComplete(fwd); + httpStateFree(-1, this); +#endif +} + +/* * build request headers and append them to a given MemBuf * used by httpBuildRequestPrefix() * note: initialised the HttpHeader, the caller is responsible for Clean()-ing @@ -2012,6 +2028,7 @@ { debug(0,0)("HttpStateData::doneAdapting() called\n"); fwdComplete(fwd); + httpStateFree(-1, this); } Index: squid3/src/http.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.h,v retrieving revision 1.11.4.3 retrieving revision 1.11.4.4 diff -u -r1.11.4.3 -r1.11.4.4 --- squid3/src/http.h 19 Aug 2005 21:58:38 -0000 1.11.4.3 +++ squid3/src/http.h 19 Aug 2005 22:57:41 -0000 1.11.4.4 @@ -1,6 +1,6 @@ /* - * $Id: http.h,v 1.11.4.3 2005/08/19 21:58:38 dwsquid Exp $ + * $Id: http.h,v 1.11.4.4 2005/08/19 22:57:41 dwsquid Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -102,6 +102,7 @@ void keepaliveAccounting(HttpReply *); void checkDateSkew(HttpReply *); void haveParsedReplyHeaders(); + void transactionComplete(); #if ICAP_CLIENT int doIcap(); #endif