--------------------- PatchSet 6293 Date: 2007/12/15 16:02:42 Author: chtsanti Branch: async-calls Tag: (none) Log: Modifing the comm_read/comm_read_cancel related code in ICAPXAction to use the new CommCalls interface. Comment: When an AsyncCall scheduled, it also stored in a variable to allow us to cancel this call if required. This approach as it is now implemented is very dangerous. At least cbdata locking should added to AsyncCall kids classes and maybe a different approach must used to cancel scheduled calls (something in the form AsyncCall->cancel()) Members: src/ICAP/ICAPXaction.cc:1.22.4.7->1.22.4.8 src/ICAP/ICAPXaction.h:1.11.14.3->1.11.14.4 Index: squid3/src/ICAP/ICAPXaction.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPXaction.cc,v retrieving revision 1.22.4.7 retrieving revision 1.22.4.8 diff -u -r1.22.4.7 -r1.22.4.8 --- squid3/src/ICAP/ICAPXaction.cc 14 Dec 2007 06:07:29 -0000 1.22.4.7 +++ squid3/src/ICAP/ICAPXaction.cc 15 Dec 2007 16:02:42 -0000 1.22.4.8 @@ -50,13 +50,6 @@ ICAPXaction_fromData(data).noteCommWrote(status, size); } -static -void ICAPXaction_noteCommRead(int, char *, size_t size, comm_err_t status, int xerrno, void *data) -{ - debugs(93,3,HERE << data << " read returned " << size); - ICAPXaction_fromData(data).noteCommRead(status, size); -} - ICAPXaction::ICAPXaction(const char *aTypeName, ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService): AsyncJob(aTypeName), ICAPInitiate(aTypeName, anInitiator, aService), @@ -300,49 +293,51 @@ Must(!reader); Must(readBuf.hasSpace()); - reader = &ICAPXaction_noteCommRead; /* * See comments in ICAPXaction.h about why we use commBuf * here instead of reading directly into readBuf.buf. */ + typedef CommCbMemFunT Dialer; + reader = asyncCall(93,3, "ICAPXaction::noteCommRead", + Dialer(this, &ICAPXaction::noteCommRead)); - comm_read(connection, commBuf, readBuf.spaceSize(), reader, this); + comm_read(connection, commBuf, readBuf.spaceSize(), reader); updateTimeout(); } // comm module read a portion of the ICAP response for us -void ICAPXaction::noteCommRead(comm_err_t commStatus, size_t sz) +void ICAPXaction::noteCommRead(const CommIoCbParams &io) { Must(reader); reader = NULL; - Must(commStatus == COMM_OK); - Must(sz >= 0); + Must(io.flag == COMM_OK); + Must(io.size >= 0); updateTimeout(); - debugs(93, 3, HERE << "read " << sz << " bytes"); + debugs(93, 3, HERE << "read " << io.size << " bytes"); /* * See comments in ICAPXaction.h about why we use commBuf * here instead of reading directly into readBuf.buf. */ - if (sz > 0) { - readBuf.append(commBuf, sz); + if (io.size > 0) { + readBuf.append(commBuf, io.size); disableRetries(); // because pconn did not fail } else { reuseConnection = false; commEof = true; } - handleCommRead(sz); + handleCommRead(io.size); } void ICAPXaction::cancelRead() { if (reader) { - comm_read_cancel(connection, reader, this); + comm_read_cancel(connection, reader); reader = NULL; } } Index: squid3/src/ICAP/ICAPXaction.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPXaction.h,v retrieving revision 1.11.14.3 retrieving revision 1.11.14.4 diff -u -r1.11.14.3 -r1.11.14.4 --- squid3/src/ICAP/ICAPXaction.h 5 Dec 2007 04:44:49 -0000 1.11.14.3 +++ squid3/src/ICAP/ICAPXaction.h 15 Dec 2007 16:02:42 -0000 1.11.14.4 @@ -1,6 +1,6 @@ /* - * $Id: ICAPXaction.h,v 1.11.14.3 2007/12/05 04:44:49 rousskov Exp $ + * $Id: ICAPXaction.h,v 1.11.14.4 2007/12/15 16:02:42 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -35,6 +35,7 @@ #define SQUID_ICAPXACTION_H #include "comm.h" +#include "CommCalls.h" #include "MemBuf.h" #include "ICAPServiceRep.h" #include "ICAPInitiate.h" @@ -64,7 +65,7 @@ // comm handler wrappers, treat as private void noteCommConnected(const CommConnectCbParams &io); void noteCommWrote(comm_err_t status, size_t sz); - void noteCommRead(comm_err_t status, size_t sz); + void noteCommRead(const CommIoCbParams &io); void noteCommTimedout(); void noteCommClosed(); @@ -137,7 +138,7 @@ // active (pending) comm callbacks for the ICAP server connection AsyncCall *connector; - IOCB *reader; + AsyncCall *reader; IOCB *writer; PF *closer;