--------------------- PatchSet 6305 Date: 2007/12/16 22:00:35 Author: chtsanti Branch: async-calls Tag: (none) Log: Adjusting comm_write calls in ServerStateData and kids classes (FtpStateData/HttpStateData) to use CommCalls Changes: - The ServerStateData::sentRequestBody (and related FtpStateData/HttpStateData m ethods) adapted to used with new CommCalls interface - The ServerStateData::sentRequestBodyWrapper not used any more, so removed - HttpStateData::SendComplete modified to be used with CommCalls - The HttpStateData::readReply modified to be used with CommCalls and scheduled directly not through ReadReplyWrapper static method - HttpStateData::ReadReplyWrapper removed, not used any more - FtpStateData::ftpWriteCommandCallback and FtpStateData::dataRead modified to be used with CommCalls - FtpStateData::dataReadWrapper static method removed not used any more Members: src/Server.cc:1.20.4.6->1.20.4.7 src/Server.h:1.10.4.6->1.10.4.7 src/ftp.cc:1.89.4.5->1.89.4.6 src/http.cc:1.122.4.3->1.122.4.4 src/http.h:1.28->1.28.4.1 Index: squid3/src/Server.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Server.cc,v retrieving revision 1.20.4.6 retrieving revision 1.20.4.7 diff -u -r1.20.4.6 -r1.20.4.7 --- squid3/src/Server.cc 5 Dec 2007 04:43:55 -0000 1.20.4.6 +++ squid3/src/Server.cc 16 Dec 2007 22:00:35 -0000 1.20.4.7 @@ -1,5 +1,5 @@ /* - * $Id: Server.cc,v 1.20.4.6 2007/12/05 04:43:55 rousskov Exp $ + * $Id: Server.cc,v 1.20.4.7 2007/12/16 22:00:35 chtsanti Exp $ * * DEBUG: * AUTHOR: Duane Wessels @@ -303,29 +303,22 @@ // kids extend this } -void -ServerStateData::sentRequestBodyWrapper(int fd, char *bufnotused, size_t size, comm_err_t errflag, int xerrno, void *data) -{ - ServerStateData *server = static_cast(data); - server->sentRequestBody(fd, size, errflag); -} - // called when we wrote request headers(!) or a part of the body void -ServerStateData::sentRequestBody(int fd, size_t size, comm_err_t errflag) +ServerStateData::sentRequestBody(const CommIoCbParams &io) { - debugs(11, 5, "sentRequestBody: FD " << fd << ": size " << size << ": errflag " << errflag << "."); + debugs(11, 5, "sentRequestBody: FD " << io.fd << ": size " << io.size << ": errflag " << io.flag << "."); debugs(32,3,HERE << "sentRequestBody called"); requestSender = NULL; - if (size > 0) { - fd_bytes(fd, size, FD_WRITE); - kb_incr(&statCounter.server.all.kbytes_out, size); + if (io.size > 0) { + fd_bytes(io.fd, io.size, FD_WRITE); + kb_incr(&statCounter.server.all.kbytes_out, io.size); // kids should increment their counters } - if (errflag == COMM_ERR_CLOSING) + if (io.flag == COMM_ERR_CLOSING) return; if (!requestBodySource) { @@ -333,8 +326,8 @@ return; // do nothing; } - if (errflag) { - debugs(11, 1, "sentRequestBody error: FD " << fd << ": " << xstrerr(errno)); + if (io.flag) { + debugs(11, 1, "sentRequestBody error: FD " << io.fd << ": " << xstrerr(errno)); ErrorState *err; err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request); err->xerrno = errno; @@ -362,8 +355,10 @@ MemBuf buf; if (requestBodySource->getMoreData(buf)) { debugs(9,3, HERE << "will write " << buf.contentSize() << " request body bytes"); - requestSender = &ServerStateData::sentRequestBodyWrapper; - comm_write_mbuf(dataDescriptor(), &buf, requestSender, this); + typedef CommCbMemFunT Dialer; + requestSender = asyncCall(93,3, "ServerStateData::sentRequestBody", + Dialer(this, &ServerStateData::sentRequestBody)); + comm_write_mbuf(dataDescriptor(), &buf, requestSender); } else { debugs(9,3, HERE << "will wait for more request body bytes or eof"); requestSender = NULL; Index: squid3/src/Server.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Server.h,v retrieving revision 1.10.4.6 retrieving revision 1.10.4.7 diff -u -r1.10.4.6 -r1.10.4.7 --- squid3/src/Server.h 16 Dec 2007 10:42:33 -0000 1.10.4.6 +++ squid3/src/Server.h 16 Dec 2007 22:00:35 -0000 1.10.4.7 @@ -1,6 +1,6 @@ /* - * $Id: Server.h,v 1.10.4.6 2007/12/16 10:42:33 chtsanti Exp $ + * $Id: Server.h,v 1.10.4.7 2007/12/16 22:00:35 chtsanti Exp $ * * AUTHOR: Duane Wessels * @@ -50,6 +50,7 @@ #include "forward.h" #include "BodyPipe.h" #include "ICAP/AsyncJob.h" +#include "CommCalls.h" #if ICAP_CLIENT #include "ICAP/ICAPServiceRep.h" @@ -132,9 +133,8 @@ // sending of the request body to the server void sendMoreRequestBody(); // has body; kids overwrite to increment I/O stats counters - virtual void sentRequestBody(int fd, size_t size, comm_err_t errflag) = 0; + virtual void sentRequestBody(const CommIoCbParams &io) = 0; virtual void doneSendingRequestBody() = 0; - static IOCB sentRequestBodyWrapper; virtual void closeServer() = 0; // end communication with the server virtual bool doneWithServer() const = 0; // did we end communication? @@ -182,7 +182,7 @@ protected: BodyPipe::Pointer requestBodySource; // to consume request body - IOCB *requestSender; // set if we are expecting comm_write to call us back + AsyncCall *requestSender; // set if we are expecting comm_write to call us back #if ICAP_CLIENT BodyPipe::Pointer virginBodyDestination; // to provide virgin response body Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.89.4.5 retrieving revision 1.89.4.6 diff -u -r1.89.4.5 -r1.89.4.6 --- squid3/src/ftp.cc 15 Dec 2007 16:21:26 -0000 1.89.4.5 +++ squid3/src/ftp.cc 16 Dec 2007 22:00:35 -0000 1.89.4.6 @@ -1,5 +1,5 @@ /* - * $Id: ftp.cc,v 1.89.4.5 2007/12/15 16:21:26 chtsanti Exp $ + * $Id: ftp.cc,v 1.89.4.6 2007/12/16 22:00:35 chtsanti Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -189,7 +189,7 @@ char *htmlifyListEntry(const char *line); void parseListing(); void dataComplete(); - void dataRead(int fd, char *buf, size_t len, comm_err_t errflag, int xerrno); + void dataRead(const CommIoCbParams &io); int checkAuth(const HttpHeader * req_hdr); void checkUrlpath(); void buildTitleUrl(); @@ -206,16 +206,15 @@ static PF ftpSocketClosed; static CNCB ftpPasvCallback; - static IOCB dataReadWrapper; static PF ftpDataWrite; static PF ftpTimeout; void ftpReadControlReply(const CommIoCbParams &io); - static IOCB ftpWriteCommandCallback; + void ftpWriteCommandCallback(const CommIoCbParams &io); static HttpReply *ftpAuthRequired(HttpRequest * request, const char *realm); static wordlist *ftpParseControlReply(char *, size_t, int *, size_t *); // sending of the request body to the server - virtual void sentRequestBody(int fd, size_t size, comm_err_t errflag); + virtual void sentRequestBody(const CommIoCbParams&); virtual void doneSendingRequestBody(); virtual void haveParsedReplyHeaders(); @@ -1189,14 +1188,6 @@ } void -FtpStateData::dataReadWrapper(int fd, char *buf, size_t len, comm_err_t errflag, int xerrno, void *data) -{ - FtpStateData *ftpState = (FtpStateData *)data; - ftpState->data.read_pending = false; - ftpState->dataRead(fd, buf, len, errflag, xerrno); -} - -void FtpStateData::maybeReadVirginBody() { if (data.fd < 0) @@ -1218,28 +1209,31 @@ debugs(9,5,HERE << "queueing read on FD " << data.fd); + typedef CommCbMemFunT Dialer; entry->delayAwareRead(data.fd, data.readBuf->space(), read_sz, - commCbCall(9,5, "dataReadWrapper", - CommIoCbPtrFun(dataReadWrapper, this))); + asyncCall(9, 5, "FtpStateData::dataRead", + Dialer(this, &FtpStateData::dataRead))); } void -FtpStateData::dataRead(int fd, char *buf, size_t len, comm_err_t errflag, int xerrno) +FtpStateData::dataRead(const CommIoCbParams &io) { int j; int bin; - debugs(9, 3, HERE << "ftpDataRead: FD " << fd << " Read " << len << " bytes"); + data.read_pending = false; - if (len > 0) { - kb_incr(&statCounter.server.all.kbytes_in, len); - kb_incr(&statCounter.server.ftp.kbytes_in, len); + debugs(9, 3, HERE << "ftpDataRead: FD " << io.fd << " Read " << io.size << " bytes"); + + if (io.size > 0) { + kb_incr(&statCounter.server.all.kbytes_in, io.size); + kb_incr(&statCounter.server.ftp.kbytes_in, io.size); } - if (errflag == COMM_ERR_CLOSING) + if (io.flag == COMM_ERR_CLOSING) return; - assert(fd == data.fd); + assert(io.fd == data.fd); #if DELAY_POOLS @@ -1252,36 +1246,36 @@ return; } - if (errflag == COMM_OK && len > 0) { + if (io.flag == COMM_OK && io.size > 0) { #if DELAY_POOLS - delayId.bytesIn(len); + delayId.bytesIn(io.size); #endif } - if (errflag == COMM_OK && len > 0) { - debugs(9,5,HERE << "appended " << len << " bytes to readBuf"); - data.readBuf->appended(len); + if (io.flag == COMM_OK && io.size > 0) { + debugs(9,5,HERE << "appended " << io.size << " bytes to readBuf"); + data.readBuf->appended(io.size); #if DELAY_POOLS DelayId delayId = entry->mem_obj->mostBytesAllowed(); - delayId.bytesIn(len); + delayId.bytesIn(io.size); #endif IOStats.Ftp.reads++; - for (j = len - 1, bin = 0; j; bin++) + for (j = io.size - 1, bin = 0; j; bin++) j >>= 1; IOStats.Ftp.read_hist[bin]++; } - if (errflag != COMM_OK || len < 0) { - debugs(50, ignoreErrno(xerrno) ? 3 : 1, "ftpDataRead: read error: " << xstrerr(xerrno)); + if (io.flag != COMM_OK || io.size < 0) { + debugs(50, ignoreErrno(io.xerrno) ? 3 : 1, "ftpDataRead: read error: " << xstrerr(io.xerrno)); - if (ignoreErrno(xerrno)) { - commSetTimeout(fd, Config.Timeout.read, ftpTimeout, this); + if (ignoreErrno(io.xerrno)) { + commSetTimeout(io.fd, Config.Timeout.read, ftpTimeout, this); maybeReadVirginBody(); } else { if (!flags.http_header_sent && !fwd->ftpPasvFailed() && flags.pasv_supported) { @@ -1293,8 +1287,8 @@ /* failed closes ctrl.fd and frees ftpState */ return; } - } else if (len == 0) { - debugs(9,5,HERE << "Calling dataComplete() because len == 0"); + } else if (io.size == 0) { + debugs(9,5,HERE << "Calling dataComplete() because io.size == 0"); /* * DPW 2007-04-23 * Dangerous curves ahead. This call to dataComplete was @@ -1567,34 +1561,34 @@ ctrl.last_command = ebuf; + typedef CommCbMemFunT Dialer; comm_write(ctrl.fd, ctrl.last_command, strlen(ctrl.last_command), - FtpStateData::ftpWriteCommandCallback, - this, NULL); + asyncCall(9, 5, "FtpStateData::ftpWriteCommandCallback", + Dialer(this, &FtpStateData::ftpWriteCommandCallback))); scheduleReadControlReply(0); } void -FtpStateData::ftpWriteCommandCallback(int fd, char *buf, size_t size, comm_err_t errflag, int xerrno, void *data) +FtpStateData::ftpWriteCommandCallback(const CommIoCbParams &io) { - FtpStateData *ftpState = (FtpStateData *)data; - debugs(9, 7, "ftpWriteCommandCallback: wrote " << size << " bytes"); + debugs(9, 7, "ftpWriteCommandCallback: wrote " << io.size << " bytes"); - if (size > 0) { - fd_bytes(fd, size, FD_WRITE); - kb_incr(&statCounter.server.all.kbytes_out, size); - kb_incr(&statCounter.server.ftp.kbytes_out, size); + if (io.size > 0) { + fd_bytes(io.fd, io.size, FD_WRITE); + kb_incr(&statCounter.server.all.kbytes_out, io.size); + kb_incr(&statCounter.server.ftp.kbytes_out, io.size); } - if (errflag == COMM_ERR_CLOSING) + if (io.flag == COMM_ERR_CLOSING) return; - if (errflag) { - debugs(9, 1, "ftpWriteCommandCallback: FD " << fd << ": " << xstrerr(xerrno)); - ftpState->failed(ERR_WRITE_ERROR, xerrno); + if (io.flag) { + debugs(9, 1, "ftpWriteCommandCallback: FD " << io.fd << ": " << xstrerr(io.xerrno)); + failed(ERR_WRITE_ERROR, io.xerrno); /* failed closes ctrl.fd and frees ftpState */ return; } @@ -2915,11 +2909,11 @@ /* This will be called when the put write is completed */ void -FtpStateData::sentRequestBody(int fd, size_t size, comm_err_t errflag) +FtpStateData::sentRequestBody(const CommIoCbParams &io) { - if (size > 0) - kb_incr(&statCounter.server.ftp.kbytes_out, size); - ServerStateData::sentRequestBody(fd, size, errflag); + if (io.size > 0) + kb_incr(&statCounter.server.ftp.kbytes_out, io.size); + ServerStateData::sentRequestBody(io); } static void Index: squid3/src/http.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.cc,v retrieving revision 1.122.4.3 retrieving revision 1.122.4.4 diff -u -r1.122.4.3 -r1.122.4.4 --- squid3/src/http.cc 29 Nov 2007 21:04:03 -0000 1.122.4.3 +++ squid3/src/http.cc 16 Dec 2007 22:00:35 -0000 1.122.4.4 @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.122.4.3 2007/11/29 21:04:03 rousskov Exp $ + * $Id: http.cc,v 1.122.4.4 2007/12/16 22:00:35 chtsanti Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -926,6 +926,7 @@ /* * This is the callback after some data has been read from the network */ +/* void HttpStateData::ReadReplyWrapper(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data) { @@ -936,19 +937,23 @@ httpState->readReply (len, flag, xerrno); PROF_stop(HttpStateData_readReply); } - +*/ /* XXX this function is too long! */ void -HttpStateData::readReply (size_t len, comm_err_t flag, int xerrno) +HttpStateData::readReply (const CommIoCbParams &io) { int bin; int clen; - flags.do_next_read = 0; + int len = io.size; + assert(fd == io.fd); + + flags.do_next_read = 0; + debugs(11, 5, "httpReadReply: FD " << fd << ": len " << len << "."); // Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us - if (flag == COMM_ERR_CLOSING) { + if (io.flag == COMM_ERR_CLOSING) { debugs(11, 3, "http socket closing"); return; } @@ -959,15 +964,15 @@ } // handle I/O errors - if (flag != COMM_OK || len < 0) { + if (io.flag != COMM_OK || len < 0) { debugs(11, 2, "httpReadReply: FD " << fd << ": read failure: " << xstrerror() << "."); - if (ignoreErrno(xerrno)) { + if (ignoreErrno(io.xerrno)) { flags.do_next_read = 1; } else { ErrorState *err; err = errorCon(ERR_READ_ERROR, HTTP_BAD_GATEWAY, fwd->request); - err->xerrno = xerrno; + err->xerrno = io.xerrno; fwd->fail(err); flags.do_next_read = 0; comm_close(fd); @@ -1218,9 +1223,11 @@ if (flags.do_next_read) { flags.do_next_read = 0; + typedef CommCbMemFunT Dialer; + entry->delayAwareRead(fd, readBuf->space(), read_sz, - commCbCall(11,5, "HttpStateData::ReadReplyWrapper", - CommIoCbPtrFun(&ReadReplyWrapper, this))); + asyncCall(11, 5, "HttpStateData::readReply", + Dialer(this, &HttpStateData::readReply))); } } @@ -1228,29 +1235,28 @@ * This will be called when request write is complete. */ void -HttpStateData::SendComplete(int fd, char *bufnotused, size_t size, comm_err_t errflag, int xerrno, void *data) +HttpStateData::sendComplete(const CommIoCbParams &io) { - HttpStateData *httpState = static_cast(data); - debugs(11, 5, "httpSendComplete: FD " << fd << ": size " << size << ": errflag " << errflag << "."); + debugs(11, 5, "httpSendComplete: FD " << fd << ": size " << io.size << ": errflag " << io.flag << "."); #if URL_CHECKSUM_DEBUG entry->mem_obj->checkUrlChecksum(); #endif - if (size > 0) { - fd_bytes(fd, size, FD_WRITE); - kb_incr(&statCounter.server.all.kbytes_out, size); - kb_incr(&statCounter.server.http.kbytes_out, size); + if (io.size > 0) { + fd_bytes(fd, io.size, FD_WRITE); + kb_incr(&statCounter.server.all.kbytes_out, io.size); + kb_incr(&statCounter.server.http.kbytes_out, io.size); } - if (errflag == COMM_ERR_CLOSING) + if (io.flag == COMM_ERR_CLOSING) return; - if (errflag) { + if (io.flag) { ErrorState *err; - err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, httpState->fwd->request); - err->xerrno = xerrno; - httpState->fwd->fail(err); + err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request); + err->xerrno = io.xerrno; + fwd->fail(err); comm_close(fd); return; } @@ -1263,9 +1269,9 @@ * the timeout for POST/PUT requests that have very large * request bodies. */ - commSetTimeout(fd, Config.Timeout.read, httpTimeout, httpState); + commSetTimeout(fd, Config.Timeout.read, httpTimeout, this); - httpState->flags.request_sent = 1; + flags.request_sent = 1; } // Close the HTTP server connection. Used by serverComplete(). @@ -1707,10 +1713,14 @@ if (orig_request->body_pipe != NULL) { if (!startRequestBodyFlow()) // register to receive body data return false; - requestSender = HttpStateData::sentRequestBodyWrapper; + typedef CommCbMemFunT Dialer; + Dialer dialer(this, &HttpStateData::sentRequestBody); + requestSender = asyncCall(11,5, "HttpStateData::sentRequestBody", dialer); } else { assert(!requestBodySource); - requestSender = HttpStateData::SendComplete; + typedef CommCbMemFunT Dialer; + Dialer dialer(this, &HttpStateData::sendComplete); + requestSender = asyncCall(11,5, "HttpStateData::SendComplete", dialer); } if (_peer != NULL) { @@ -1750,7 +1760,7 @@ mb.init(); buildRequestPrefix(request, orig_request, entry, &mb, flags); debugs(11, 6, "httpSendRequest: FD " << fd << ":\n" << mb.buf); - comm_write_mbuf(fd, &mb, requestSender, this); + comm_write_mbuf(fd, &mb, requestSender); return true; } @@ -1791,13 +1801,21 @@ if (!Config.accessList.brokenPosts) { debugs(11, 5, "doneSendingRequestBody: No brokenPosts list"); - HttpStateData::SendComplete(fd, NULL, 0, COMM_OK, 0, this); + CommIoCbParams io(NULL); + io.fd=fd; + io.flag=COMM_OK; + sendComplete(io); } else if (!ch.fastCheck()) { debugs(11, 5, "doneSendingRequestBody: didn't match brokenPosts"); - HttpStateData::SendComplete(fd, NULL, 0, COMM_OK, 0, this); + CommIoCbParams io(NULL); + io.fd=fd; + io.flag=COMM_OK; + sendComplete(io); } else { debugs(11, 2, "doneSendingRequestBody: matched brokenPosts"); - comm_write(fd, "\r\n", 2, HttpStateData::SendComplete, this, NULL); + typedef CommCbMemFunT Dialer; + Dialer dialer(this, &HttpStateData::sendComplete); + comm_write(fd, "\r\n", 2, asyncCall(11,5, "HttpStateData::SendComplete", dialer)); } } @@ -1838,17 +1856,20 @@ { ServerStateData::handleRequestBodyProducerAborted(); // XXX: SendComplete(COMM_ERR_CLOSING) does little. Is it enough? - SendComplete(fd, NULL, 0, COMM_ERR_CLOSING, 0, this); + CommIoCbParams io(NULL); + io.fd=fd; + io.flag=COMM_ERR_CLOSING; + sendComplete(io); } // called when we wrote request headers(!) or a part of the body void -HttpStateData::sentRequestBody(int fd, size_t size, comm_err_t errflag) +HttpStateData::sentRequestBody(const CommIoCbParams &io) { - if (size > 0) - kb_incr(&statCounter.server.http.kbytes_out, size); + if (io.size > 0) + kb_incr(&statCounter.server.http.kbytes_out, io.size); - ServerStateData::sentRequestBody(fd, size, errflag); + ServerStateData::sentRequestBody(io); } // Quickly abort the transaction Index: squid3/src/http.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.h,v retrieving revision 1.28 retrieving revision 1.28.4.1 diff -u -r1.28 -r1.28.4.1 --- squid3/src/http.h 9 Aug 2007 23:51:11 -0000 1.28 +++ squid3/src/http.h 16 Dec 2007 22:00:35 -0000 1.28.4.1 @@ -1,6 +1,6 @@ /* - * $Id: http.h,v 1.28 2007/08/09 23:51:11 squidadm Exp $ + * $Id: http.h,v 1.28.4.1 2007/12/16 22:00:35 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -46,8 +46,6 @@ HttpStateData(FwdState *); ~HttpStateData(); - static IOCB SendComplete; - static IOCB ReadReplyWrapper; static void httpBuildRequestHeader(HttpRequest * request, HttpRequest * orig_request, StoreEntry * entry, @@ -59,7 +57,7 @@ bool sendRequest(); void processReplyHeader(); void processReplyBody(); - void readReply(size_t len, comm_err_t flag, int xerrno); + void readReply(const CommIoCbParams &io); virtual void maybeReadVirginBody(); // read response data from the network int cacheableReply(); @@ -105,7 +103,8 @@ void writeReplyBody(); void doneSendingRequestBody(); void requestBodyHandler(MemBuf &); - virtual void sentRequestBody(int fd, size_t size, comm_err_t errflag); + virtual void sentRequestBody(const CommIoCbParams &io); + void sendComplete(const CommIoCbParams &io); mb_size_t buildRequestPrefix(HttpRequest * request, HttpRequest * orig_request, StoreEntry * entry,