--------------------- PatchSet 5998 Date: 2007/10/23 20:27:51 Author: chtsanti Branch: async-calls Tag: (none) Log: -Adjust ClientHttpRequest, ConnStateData and ServerStateData implement AsyncJob interface, using AsyncJob as a virtual base class. -Renaming ClientHttpRequest::start to ClientHttpRequest::start_time, conficts with AsyncJob::start() method -Don not do "delete this" in HttpStateData::abortTransaction, FtpStateData::abortTransaction and ServerStateData::quitIfAllDone if we are in the midle of AsyncC all, but instead call AsyncJob::mustStop method Members: src/Server.cc:1.20->1.20.4.1 src/Server.h:1.10->1.10.4.1 src/client_side.cc:1.139->1.139.4.1 src/client_side.h:1.22->1.22.4.1 src/client_side_request.cc:1.79->1.79.4.1 src/client_side_request.h:1.30->1.30.4.1 src/ftp.cc:1.89->1.89.4.1 src/http.cc:1.122->1.122.4.1 src/stat.cc:1.44->1.44.4.1 src/ICAP/AsyncJob.cc:1.3.4.2->1.3.4.3 Index: squid3/src/Server.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Server.cc,v retrieving revision 1.20 retrieving revision 1.20.4.1 diff -u -r1.20 -r1.20.4.1 --- squid3/src/Server.cc 27 Sep 2007 14:51:35 -0000 1.20 +++ squid3/src/Server.cc 23 Oct 2007 20:27:51 -0000 1.20.4.1 @@ -1,5 +1,5 @@ /* - * $Id: Server.cc,v 1.20 2007/09/27 14:51:35 squidadm Exp $ + * $Id: Server.cc,v 1.20.4.1 2007/10/23 20:27:51 chtsanti Exp $ * * DEBUG: * AUTHOR: Duane Wessels @@ -45,7 +45,7 @@ extern ICAPConfig TheICAPConfig; #endif -ServerStateData::ServerStateData(FwdState *theFwdState): requestSender(NULL) +ServerStateData::ServerStateData(FwdState *theFwdState): AsyncJob("ServerStateData"),requestSender(NULL) #if ICAP_CLIENT , icapAccessCheckPending(false) #endif @@ -178,7 +178,11 @@ } debugs(11,3, HERE << "transaction done"); - delete this; + + if(inCall) + mustStop("ServerStateData::quitIfAllDone"); + else + delete this; } // FTP side overloads this to work around multiple calls to fwd->complete @@ -603,7 +607,6 @@ } completeForwarding(); - quitIfAllDone(); } Index: squid3/src/Server.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Server.h,v retrieving revision 1.10 retrieving revision 1.10.4.1 diff -u -r1.10 -r1.10.4.1 --- squid3/src/Server.h 27 Sep 2007 14:51:35 -0000 1.10 +++ squid3/src/Server.h 23 Oct 2007 20:27:51 -0000 1.10.4.1 @@ -1,6 +1,6 @@ /* - * $Id: Server.h,v 1.10 2007/09/27 14:51:35 squidadm Exp $ + * $Id: Server.h,v 1.10.4.1 2007/10/23 20:27:51 chtsanti Exp $ * * AUTHOR: Duane Wessels * @@ -49,6 +49,7 @@ #include "StoreIOBuffer.h" #include "forward.h" #include "BodyPipe.h" +#include "ICAP/AsyncJob.h" #if ICAP_CLIENT #include "ICAP/ICAPServiceRep.h" @@ -58,6 +59,7 @@ #endif class ServerStateData: + virtual public AsyncJob, #if ICAP_CLIENT public ICAPInitiator, public BodyProducer, @@ -102,6 +104,13 @@ #endif virtual void processReplyBody() = 0; +//AsyncJob virtual methods + virtual void start(){/*Just Do nothing*/} + virtual bool doneAll() const { assert(false); return false;} + virtual void swanSong(){/*Just Do nothing*/} + virtual const char* status() const {return "Maybe OK!";} + virtual void *toCbdata() {return this;} + public: // should be protected void serverComplete(); // call when no server communication is expected Index: squid3/src/client_side.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side.cc,v retrieving revision 1.139 retrieving revision 1.139.4.1 diff -u -r1.139 -r1.139.4.1 --- squid3/src/client_side.cc 28 Sep 2007 00:51:10 -0000 1.139 +++ squid3/src/client_side.cc 23 Oct 2007 20:27:51 -0000 1.139.4.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.139 2007/09/28 00:51:10 squidadm Exp $ + * $Id: client_side.cc,v 1.139.4.1 2007/10/23 20:27:51 chtsanti Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -433,7 +433,7 @@ statCounter.client_http.errors++; clientUpdateStatHistCounters(logType, - tvSubMsec(start, current_time)); + tvSubMsec(start_time, current_time)); clientUpdateHierCounters(&request->hier); } @@ -500,7 +500,7 @@ al.cache.code = logType; - al.cache.msec = tvSubMsec(start, current_time); + al.cache.msec = tvSubMsec(start_time, current_time); if (request) clientPrepareLogWithRequestDetails(request, &al); @@ -3181,7 +3181,7 @@ CBDATA_CLASS_INIT(ConnStateData); -ConnStateData::ConnStateData() : transparent_ (false), reading_ (false), closing_ (false) +ConnStateData::ConnStateData() :AsyncJob("ConnStateData"), transparent_ (false), reading_ (false), closing_ (false) { openReference = this; } Index: squid3/src/client_side.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side.h,v retrieving revision 1.22 retrieving revision 1.22.4.1 diff -u -r1.22 -r1.22.4.1 --- squid3/src/client_side.h 28 Sep 2007 00:51:10 -0000 1.22 +++ squid3/src/client_side.h 23 Oct 2007 20:27:52 -0000 1.22.4.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side.h,v 1.22 2007/09/28 00:51:10 squidadm Exp $ + * $Id: client_side.h,v 1.22.4.1 2007/10/23 20:27:52 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -38,6 +38,7 @@ #include "StoreIOBuffer.h" #include "BodyPipe.h" #include "RefCount.h" +#include "ICAP/AsyncJob.h" class ConnStateData; @@ -128,7 +129,7 @@ /* A connection to a socket */ -class ConnStateData : public BodyProducer, public RefCountable +class ConnStateData : virtual public AsyncJob, public BodyProducer, public RefCountable { public: @@ -210,6 +211,12 @@ void handleReadData(char *buf, size_t size); void handleRequestBodyData(); +//AsyncJob virtual classes + virtual void start(){/*Just Do nothing*/} + virtual bool doneAll() const { assert(false); return false;} + virtual void swanSong(){/*Just Do nothing*/} + virtual const char* status() const {return "Maybe OK!";} + private: CBDATA_CLASS2(ConnStateData); bool transparent_; Index: squid3/src/client_side_request.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side_request.cc,v retrieving revision 1.79 retrieving revision 1.79.4.1 diff -u -r1.79 -r1.79.4.1 --- squid3/src/client_side_request.cc 27 Sep 2007 22:51:55 -0000 1.79 +++ squid3/src/client_side_request.cc 23 Oct 2007 20:27:52 -0000 1.79.4.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.cc,v 1.79 2007/09/27 22:51:55 squidadm Exp $ + * $Id: client_side_request.cc,v 1.79.4.1 2007/10/23 20:27:52 chtsanti Exp $ * * DEBUG: section 85 Client-side Request Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -142,9 +142,9 @@ cbdataFree(t); } -ClientHttpRequest::ClientHttpRequest(ConnStateData::Pointer aConn) : loggingEntry_(NULL) +ClientHttpRequest::ClientHttpRequest(ConnStateData::Pointer aConn) : AsyncJob("ClientHttpRequest"),loggingEntry_(NULL) { - start = current_time; + start_time = current_time; setConn(aConn); dlinkAdd(this, &active, &ClientActiveRequests); #if ICAP_CLIENT @@ -280,7 +280,7 @@ ClientHttpRequest *http = new ClientHttpRequest(NULL); HttpRequest *request; StoreIOBuffer tempBuffer; - http->start = current_time; + http->start_time = current_time; /* this is only used to adjust the connection offset in client_side.c */ http->req_sz = 0; tempBuffer.length = taillen; Index: squid3/src/client_side_request.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side_request.h,v retrieving revision 1.30 retrieving revision 1.30.4.1 diff -u -r1.30 -r1.30.4.1 --- squid3/src/client_side_request.h 13 Aug 2007 17:24:15 -0000 1.30 +++ squid3/src/client_side_request.h 23 Oct 2007 20:27:52 -0000 1.30.4.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.h,v 1.30 2007/08/13 17:24:15 squidadm Exp $ + * $Id: client_side_request.h,v 1.30.4.1 2007/10/23 20:27:52 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -41,6 +41,7 @@ #include "client_side.h" #include "AccessLogEntry.h" #include "dlink.h" +#include "ICAP/AsyncJob.h" #if ICAP_CLIENT #include "ICAP/ICAPServiceRep.h" @@ -58,9 +59,10 @@ class ClientRequestContext; -class ClientHttpRequest +class ClientHttpRequest: + virtual public AsyncJob #if ICAP_CLIENT - : public ICAPInitiator, // to start ICAP transactions + ,public ICAPInitiator, // to start ICAP transactions public BodyConsumer // to receive reply bodies in request satisf. mode #endif { @@ -109,7 +111,7 @@ size_t req_sz; /* raw request size on input, not current request size */ log_type logType; - struct timeval start; + struct timeval start_time; AccessLogEntry al; struct @@ -151,6 +153,12 @@ ClientRequestContext *calloutContext; void doCallouts(); +//AsyncJob virtual methods + virtual void start(){/*Just Do nothing*/} + virtual bool doneAll() const { assert(false); return false;} + virtual void swanSong(){/*Just Do nothing*/} + virtual const char* status() const {return "Maybe OK!";} + private: CBDATA_CLASS(ClientHttpRequest); int64_t maxReplyBodySize_; Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.89 retrieving revision 1.89.4.1 diff -u -r1.89 -r1.89.4.1 --- squid3/src/ftp.cc 27 Sep 2007 14:51:36 -0000 1.89 +++ squid3/src/ftp.cc 23 Oct 2007 20:27:52 -0000 1.89.4.1 @@ -1,5 +1,5 @@ /* - * $Id: ftp.cc,v 1.89 2007/09/27 14:51:36 squidadm Exp $ + * $Id: ftp.cc,v 1.89.4.1 2007/10/23 20:27:52 chtsanti Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -361,7 +361,7 @@ delete ftpState; } -FtpStateData::FtpStateData(FwdState *theFwdState) : ServerStateData(theFwdState) +FtpStateData::FtpStateData(FwdState *theFwdState) : AsyncJob("FtpStateData"), ServerStateData(theFwdState) { const char *url = entry->url(); debugs(9, 3, "ftpStart: '" << url << "'" ); @@ -3429,5 +3429,8 @@ } fwd->handleUnregisteredServerEnd(); - delete this; + if (inCall) + mustStop("FtpStateData::abortTransaction"); + else + delete this; } Index: squid3/src/http.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.cc,v retrieving revision 1.122 retrieving revision 1.122.4.1 diff -u -r1.122 -r1.122.4.1 --- squid3/src/http.cc 27 Sep 2007 14:51:36 -0000 1.122 +++ squid3/src/http.cc 23 Oct 2007 20:27:55 -0000 1.122.4.1 @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.122 2007/09/27 14:51:36 squidadm Exp $ + * $Id: http.cc,v 1.122.4.1 2007/10/23 20:27:55 chtsanti Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -67,7 +67,7 @@ static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, String strConnection, HttpRequest * request, HttpRequest * orig_request, HttpHeader * hdr_out, int we_do_ranges, http_state_flags); -HttpStateData::HttpStateData(FwdState *theFwdState) : ServerStateData(theFwdState), +HttpStateData::HttpStateData(FwdState *theFwdState) : AsyncJob("HttpStateData"), ServerStateData(theFwdState), header_bytes_read(0), reply_bytes_read(0) { debugs(11,5,HERE << "HttpStateData " << this << " created"); @@ -1864,7 +1864,10 @@ } fwd->handleUnregisteredServerEnd(); - delete this; + if (inCall) + mustStop("HttpStateData::abortTransaction"); + else + delete this; } void Index: squid3/src/stat.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/stat.cc,v retrieving revision 1.44 retrieving revision 1.44.4.1 diff -u -r1.44 -r1.44.4.1 --- squid3/src/stat.cc 20 Sep 2007 20:51:57 -0000 1.44 +++ squid3/src/stat.cc 23 Oct 2007 20:27:55 -0000 1.44.4.1 @@ -1,5 +1,5 @@ /* - * $Id: stat.cc,v 1.44 2007/09/20 20:51:57 squidadm Exp $ + * $Id: stat.cc,v 1.44.4.1 2007/10/23 20:27:55 chtsanti Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -1683,9 +1683,9 @@ #endif storeAppendPrintf(s, "start %ld.%06d (%f seconds ago)\n", - (long int) http->start.tv_sec, - (int) http->start.tv_usec, - tvSubDsec(http->start, current_time)); + (long int) http->start_time.tv_sec, + (int) http->start_time.tv_usec, + tvSubDsec(http->start_time, current_time)); if (http->request->auth_user_request) p = http->request->auth_user_request->username(); Index: squid3/src/ICAP/AsyncJob.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/AsyncJob.cc,v retrieving revision 1.3.4.2 retrieving revision 1.3.4.3 diff -u -r1.3.4.2 -r1.3.4.3 --- squid3/src/ICAP/AsyncJob.cc 22 Oct 2007 19:24:27 -0000 1.3.4.2 +++ squid3/src/ICAP/AsyncJob.cc 23 Oct 2007 20:27:56 -0000 1.3.4.3 @@ -187,8 +187,8 @@ swanSong(); void *cbdata = this->toCbdata(); - delete this; // this is the only place where the object is deleted cbdataReferenceDone(cbdata); // locked by AsyncStart + delete this; // this is the only place where the object is deleted // careful: this object does not exist any more debugs(93, 6, HERE << typeNameSaved << "::" << inCallSaved <<