--------------------- PatchSet 6553 Date: 2008/01/19 19:30:37 Author: chtsanti Branch: async-calls Tag: (none) Log: Converting the commSetTimeout calls to use AsyncCalls instead of functions or static method as handlers: - ftp.cc: the FtpStateData::ftpTimeout is not a static method any more - http.cc: the httpTimeout function replaced by the HttpStateData::httpTimeout method - ICAP/ICAPXaction.cc: The wrapper function ICAPXaction_noteCommTimedout does not needed any more as timeout handler, the AsyncCalls used instead Members: src/ftp.cc:1.89.4.10->1.89.4.11 src/http.cc:1.122.4.7->1.122.4.8 src/http.h:1.28.4.3->1.28.4.4 src/ICAP/ICAPXaction.cc:1.22.4.12->1.22.4.13 src/ICAP/ICAPXaction.h:1.11.14.7->1.11.14.8 Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.89.4.10 retrieving revision 1.89.4.11 diff -u -r1.89.4.10 -r1.89.4.11 --- squid3/src/ftp.cc 15 Jan 2008 19:28:44 -0000 1.89.4.10 +++ squid3/src/ftp.cc 19 Jan 2008 19:30:37 -0000 1.89.4.11 @@ -1,5 +1,5 @@ /* - * $Id: ftp.cc,v 1.89.4.10 2008/01/15 19:28:44 chtsanti Exp $ + * $Id: ftp.cc,v 1.89.4.11 2008/01/19 19:30:37 chtsanti Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -209,7 +209,7 @@ static CNCB ftpPasvCallback; static PF ftpDataWrite; - static PF ftpTimeout; + void ftpTimeout(const CommTimeoutCbParams &io); void ftpSocketClosed(const CommCloseCbParams &io); void ftpReadControlReply(const CommIoCbParams &io); void ftpWriteCommandCallback(const CommIoCbParams &io); @@ -485,20 +485,18 @@ } void -FtpStateData::ftpTimeout(int fd, void *data) +FtpStateData::ftpTimeout(const CommTimeoutCbParams &io) { - FtpStateData *ftpState = (FtpStateData *)data; - StoreEntry *entry = ftpState->entry; - debugs(9, 4, "ftpTimeout: FD " << fd << ": '" << entry->url() << "'" ); + debugs(9, 4, "ftpTimeout: FD " << io.fd << ": '" << entry->url() << "'" ); - if (SENT_PASV == ftpState->state && fd == ftpState->data.fd) { + if (SENT_PASV == state && io.fd == data.fd) { /* stupid ftp.netscape.com */ - ftpState->fwd->dontRetry(false); - ftpState->fwd->ftpPasvFailed(true); + fwd->dontRetry(false); + fwd->ftpPasvFailed(true); debugs(9, 1, "ftpTimeout: timeout in SENT_PASV state" ); } - ftpState->failed(ERR_READ_TIMEOUT, 0); + failed(ERR_READ_TIMEOUT, 0); /* failed() closes ctrl.fd and frees ftpState */ } @@ -1218,7 +1216,10 @@ data.read_pending = true; - commSetTimeout(data.fd, Config.Timeout.read, ftpTimeout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(this,&FtpStateData::ftpTimeout)); + commSetTimeout(data.fd, Config.Timeout.read, timeoutCall); debugs(9,5,HERE << "queueing read on FD " << data.fd); @@ -1288,7 +1289,11 @@ debugs(50, ignoreErrno(io.xerrno) ? 3 : 1, "ftpDataRead: read error: " << xstrerr(io.xerrno)); if (ignoreErrno(io.xerrno)) { - commSetTimeout(io.fd, Config.Timeout.read, ftpTimeout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(this,&FtpStateData::ftpTimeout)); + commSetTimeout(io.fd, Config.Timeout.read, timeoutCall); + maybeReadVirginBody(); } else { if (!flags.http_header_sent && !fwd->ftpPasvFailed() && flags.pasv_supported) { @@ -1720,11 +1725,16 @@ * establish one on the control socket. */ - if (data.fd > -1) - commSetTimeout(data.fd, -1, NULL, NULL); + if (data.fd > -1){ + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(data.fd, -1, nullCall); + } + + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(this,&FtpStateData::ftpTimeout)); - commSetTimeout(ctrl.fd, Config.Timeout.read, ftpTimeout, - this); + commSetTimeout(ctrl.fd, Config.Timeout.read, timeoutCall); } } @@ -2336,7 +2346,11 @@ * ugly hack for ftp servers like ftp.netscape.com that sometimes * dont acknowledge PASV commands. */ - commSetTimeout(ftpState->data.fd, 15, FtpStateData::ftpTimeout, ftpState); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(ftpState,&FtpStateData::ftpTimeout)); + + commSetTimeout(ftpState->data.fd, 15, timeoutCall); } void @@ -2710,9 +2724,13 @@ io.details.peer.NtoA(data.host,SQUIDHOSTNAMELEN); - commSetTimeout(ctrl.fd, -1, NULL, NULL); + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(ctrl.fd, -1, nullCall); - commSetTimeout(data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(this,&FtpStateData::ftpTimeout)); + commSetTimeout(data.fd, Config.Timeout.read, timeoutCall); /* XXX We should have a flag to track connect state... * host NULL -> not connected, port == local port @@ -2792,9 +2810,14 @@ * Cancel the timeout on the Control socket and * establish one on the data socket. */ - commSetTimeout(ctrl.fd, -1, NULL, NULL); - commSetTimeout(data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, - this); + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(ctrl.fd, -1, nullCall); + + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(this,&FtpStateData::ftpTimeout)); + + commSetTimeout(data.fd, Config.Timeout.read, timeoutCall); state = WRITING_DATA; debugs(9, 3, "ftpReadStor: writing data channel"); @@ -2921,7 +2944,8 @@ * Cancel the timeout on the Control socket and establish one * on the data socket */ - commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(ftpState->ctrl.fd, -1, nullCall); return; } else if (code == 150) { /* Accept data channel */ @@ -2934,8 +2958,13 @@ * Cancel the timeout on the Control socket and establish one * on the data socket */ - commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); - commSetTimeout(ftpState->data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, ftpState); + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(ftpState->ctrl.fd, -1, nullCall); + + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(ftpState,&FtpStateData::ftpTimeout)); + commSetTimeout(ftpState->data.fd, Config.Timeout.read, timeoutCall); return; } else if (!ftpState->flags.tried_nlst && code > 300) { ftpSendNlst(ftpState); @@ -2974,7 +3003,8 @@ * Cancel the timeout on the Control socket and establish one * on the data socket */ - commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(ftpState->ctrl.fd, -1, nullCall); } else if (code == 150) { /* Accept data channel */ typedef CommCbMemFunT acceptDialer; @@ -2985,9 +3015,13 @@ * Cancel the timeout on the Control socket and establish one * on the data socket */ - commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); - commSetTimeout(ftpState->data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, - ftpState); + AsyncCall::Pointer nullCall = NULL; + commSetTimeout(ftpState->ctrl.fd, -1, nullCall); + + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(9, 5, "FtpStateData::ftpTimeout", + TimeoutDialer(ftpState,&FtpStateData::ftpTimeout)); + commSetTimeout(ftpState->data.fd, Config.Timeout.read, timeoutCall); } else if (code >= 300) { if (!ftpState->flags.try_slash_hack) { /* Try this as a directory missing trailing slash... */ Index: squid3/src/http.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.cc,v retrieving revision 1.122.4.7 retrieving revision 1.122.4.8 diff -u -r1.122.4.7 -r1.122.4.8 --- squid3/src/http.cc 29 Dec 2007 15:24:42 -0000 1.122.4.7 +++ squid3/src/http.cc 19 Jan 2008 19:30:38 -0000 1.122.4.8 @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.122.4.7 2007/12/29 15:24:42 chtsanti Exp $ + * $Id: http.cc,v 1.122.4.8 2008/01/19 19:30:38 chtsanti Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -71,8 +71,6 @@ static const char *const crlf = "\r\n"; -//static PF httpStateFree; -static PF httpTimeout; static void httpMaybeRemovePublic(StoreEntry *, http_status); static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, String strConnection, HttpRequest * request, HttpRequest * orig_request, HttpHeader * hdr_out, int we_do_ranges, http_state_flags); @@ -192,15 +190,13 @@ return 1; } -static void -httpTimeout(int fd, void *data) +void +HttpStateData::httpTimeout(const CommTimeoutCbParams ¶ms) { - HttpStateData *httpState = static_cast(data); - StoreEntry *entry = httpState->entry; debugs(11, 4, "httpTimeout: FD " << fd << ": '" << entry->url() << "'" ); if (entry->store_status == STORE_PENDING) { - httpState->fwd->fail(errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, httpState->fwd->request)); + fwd->fail(errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, fwd->request)); } comm_close(fd); @@ -1175,7 +1171,7 @@ void HttpStateData::processReplyBody() { - + AsyncCall::Pointer call; IPAddress client_addr; if (!flags.headers_parsed) { @@ -1214,15 +1210,15 @@ (void) 0; } else switch (persistentConnStatus()) { - case INCOMPLETE_MSG: debugs(11, 5, "processReplyBody: INCOMPLETE_MSG"); /* Wait for more data or EOF condition */ - if (flags.keepalive_broken) { - commSetTimeout(fd, 10, NULL, NULL); + call = NULL; + commSetTimeout(fd, 10, call); } else { - commSetTimeout(fd, Config.Timeout.read, NULL, NULL); + call = NULL; + commSetTimeout(fd, Config.Timeout.read, call); } flags.do_next_read = 1; @@ -1231,7 +1227,8 @@ case COMPLETE_PERSISTENT_MSG: debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG"); /* yes we have to clear all these! */ - commSetTimeout(fd, -1, NULL, NULL); + call = NULL; + commSetTimeout(fd, -1, call); flags.do_next_read = 0; comm_remove_close_handler(fd, closeHandler); @@ -1334,7 +1331,11 @@ * the timeout for POST/PUT requests that have very large * request bodies. */ - commSetTimeout(fd, Config.Timeout.read, httpTimeout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(11, 5, "HttpStateData::httpTimeout", + TimeoutDialer(this,&HttpStateData::httpTimeout)); + + commSetTimeout(fd, Config.Timeout.read, timeoutCall); flags.request_sent = 1; } @@ -1775,8 +1776,10 @@ MemBuf mb; debugs(11, 5, "httpSendRequest: FD " << fd << ", request " << request << ", this " << this << "."); - - commSetTimeout(fd, Config.Timeout.lifetime, httpTimeout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(11, 5, "HttpStateData::httpTimeout", + TimeoutDialer(this,&HttpStateData::httpTimeout)); + commSetTimeout(fd, Config.Timeout.lifetime, timeoutCall); flags.do_next_read = 1; maybeReadVirginBody(); Index: squid3/src/http.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.h,v retrieving revision 1.28.4.3 retrieving revision 1.28.4.4 diff -u -r1.28.4.3 -r1.28.4.4 --- squid3/src/http.h 29 Dec 2007 15:24:42 -0000 1.28.4.3 +++ squid3/src/http.h 19 Jan 2008 19:30:38 -0000 1.28.4.4 @@ -1,6 +1,6 @@ /* - * $Id: http.h,v 1.28.4.3 2007/12/29 15:24:42 chtsanti Exp $ + * $Id: http.h,v 1.28.4.4 2008/01/19 19:30:38 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -109,6 +109,7 @@ virtual void sentRequestBody(const CommIoCbParams &io); void sendComplete(const CommIoCbParams &io); void httpStateConnClosed(const CommCloseCbParams ¶ms); + void httpTimeout(const CommTimeoutCbParams ¶ms); mb_size_t buildRequestPrefix(HttpRequest * request, HttpRequest * orig_request, Index: squid3/src/ICAP/ICAPXaction.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPXaction.cc,v retrieving revision 1.22.4.12 retrieving revision 1.22.4.13 diff -u -r1.22.4.12 -r1.22.4.13 --- squid3/src/ICAP/ICAPXaction.cc 29 Dec 2007 15:25:58 -0000 1.22.4.12 +++ squid3/src/ICAP/ICAPXaction.cc 19 Jan 2008 19:30:38 -0000 1.22.4.13 @@ -17,24 +17,6 @@ //CBDATA_CLASS_INIT(ICAPXaction); -/* comm module handlers (wrappers around corresponding ICAPXaction methods */ - -// TODO: These should be replaced with direct method calls. - -static -ICAPXaction &ICAPXaction_fromData(void *data) -{ - ICAPXaction *x = static_cast(data); - assert(x); - return *x; -} - -static -void ICAPXaction_noteCommTimedout(int, void *data) -{ - ICAPXaction_fromData(data).noteCommTimedout(); -} - ICAPXaction::ICAPXaction(const char *aTypeName, ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService): AsyncJob(aTypeName), ICAPInitiate(aTypeName, anInitiator, aService), @@ -112,17 +94,20 @@ debugs(93,3, typeName << " opens connection to " << s.host.buf() << ":" << s.port); // TODO: service bypass status may differ from that of a transaction - commSetTimeout(connection, TheICAPConfig.connect_timeout(service().bypass), - &ICAPXaction_noteCommTimedout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer timeoutCall = asyncCall(93, 5, "ICAPXaction::noteCommTimedout", + TimeoutDialer(this,&ICAPXaction::noteCommTimedout)); + + commSetTimeout(connection, TheICAPConfig.connect_timeout(service().bypass), timeoutCall); typedef CommCbMemFunT CloseDialer; closer = asyncCall(93, 5, "ICAPXaction::noteCommClosed", CloseDialer(this,&ICAPXaction::noteCommClosed)); comm_add_close_handler(connection, closer); - typedef CommCbMemFunT Dialer; + typedef CommCbMemFunT ConnectDialer; connector = asyncCall(93,3, "ICAPXaction::noteCommConnected", - Dialer(this, &ICAPXaction::noteCommConnected)); + ConnectDialer(this, &ICAPXaction::noteCommConnected)); commConnectStart(connection, s.host.buf(), s.port, connector); } @@ -159,7 +144,8 @@ if (reuseConnection) { IPAddress client_addr; debugs(93,3, HERE << "pushing pconn" << status()); - commSetTimeout(connection, -1, NULL, NULL); + AsyncCall::Pointer call = NULL; + commSetTimeout(connection, -1, call); icapPconnPool->push(connection, theService->host.buf(), theService->port, NULL, client_addr); disableRetries(); } else { @@ -224,7 +210,7 @@ } // communication timeout with the ICAP service -void ICAPXaction::noteCommTimedout() +void ICAPXaction::noteCommTimedout(const CommTimeoutCbParams &io) { handleCommTimedout(); } @@ -272,12 +258,16 @@ // restart the timeout before each I/O // XXX: why does Config.Timeout lacks a write timeout? // TODO: service bypass status may differ from that of a transaction - commSetTimeout(connection, TheICAPConfig.io_timeout(service().bypass), - &ICAPXaction_noteCommTimedout, this); + typedef CommCbMemFunT TimeoutDialer; + AsyncCall::Pointer call = asyncCall(93, 5, "ICAPXaction::noteCommTimedout", + TimeoutDialer(this,&ICAPXaction::noteCommTimedout)); + + commSetTimeout(connection, TheICAPConfig.io_timeout(service().bypass), call); } else { // clear timeout when there is no I/O // Do we need a lifetime timeout? - commSetTimeout(connection, -1, NULL, NULL); + AsyncCall::Pointer call = NULL; + commSetTimeout(connection, -1, call); } } Index: squid3/src/ICAP/ICAPXaction.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPXaction.h,v retrieving revision 1.11.14.7 retrieving revision 1.11.14.8 diff -u -r1.11.14.7 -r1.11.14.8 --- squid3/src/ICAP/ICAPXaction.h 28 Dec 2007 14:29:25 -0000 1.11.14.7 +++ squid3/src/ICAP/ICAPXaction.h 19 Jan 2008 19:30:38 -0000 1.11.14.8 @@ -1,6 +1,6 @@ /* - * $Id: ICAPXaction.h,v 1.11.14.7 2007/12/28 14:29:25 chtsanti Exp $ + * $Id: ICAPXaction.h,v 1.11.14.8 2008/01/19 19:30:38 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -66,7 +66,7 @@ void noteCommConnected(const CommConnectCbParams &io); void noteCommWrote(const CommIoCbParams &io); void noteCommRead(const CommIoCbParams &io); - void noteCommTimedout(); + void noteCommTimedout(const CommTimeoutCbParams &io); void noteCommClosed(const CommCloseCbParams &io); protected: