--------------------- PatchSet 1898 Date: 2005/09/29 05:17:21 Author: rousskov Branch: squid3-icap Tag: (none) Log: - Initialized commBuf and bodyParser. - Renamed ICAPXaction.state.is{Reading,Writing} to ICAPXaction.reader,writer and moved state.closer to ICAPXaction to better match their semantics as they are not [just] state flags. This change should have no effect on compiled code. - Documented state.* members. Members: src/ICAPXaction.cc:1.1.2.32->1.1.2.33 src/ICAPXaction.h:1.1.2.17->1.1.2.18 Index: squid3/src/ICAPXaction.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPXaction.cc,v retrieving revision 1.1.2.32 retrieving revision 1.1.2.33 diff -u -r1.1.2.32 -r1.1.2.33 --- squid3/src/ICAPXaction.cc 27 Sep 2005 20:40:57 -0000 1.1.2.32 +++ squid3/src/ICAPXaction.cc 29 Sep 2005 05:17:21 -0000 1.1.2.33 @@ -105,7 +105,10 @@ } ICAPXaction::ICAPXaction(): self(NULL), virgin(NULL), adapted(NULL), - icapReply(NULL), service(NULL), connection(-1), notify(notifyUnknown) + icapReply(NULL), service(NULL), connection(-1), + commBuf(NULL), reader(NULL), writer(NULL), closer(NULL), + bodyParser(NULL), + notify(notifyUnknown) {} ICAPXaction::~ICAPXaction() @@ -183,8 +186,8 @@ commSetTimeout(connection, Config.Timeout.connect, &ICAPXaction_noteCommTimeout, this); - state.closer = &ICAPXaction_noteCommClose; - comm_add_close_handler(connection, state.closer, this); + closer = &ICAPXaction_noteCommClose; + comm_add_close_handler(connection, closer, this); commConnectStart(connection, service->host.buf(), service->port, &ICAPXaction_noteCommConnected, this); } @@ -194,9 +197,9 @@ if (connection >= 0) { commSetTimeout(connection, -1, NULL, NULL); - if (state.closer) { - comm_remove_close_handler(connection, state.closer, this); - state.closer = NULL; + if (closer) { + comm_remove_close_handler(connection, closer, this); + closer = NULL; } stopReading(); @@ -220,9 +223,9 @@ requestBuf.init(); makeRequestHeaders(&requestBuf); // write headers only; comm module will free the requestBuf - state.isWriting = &ICAPXaction_noteCommWroteHeaders; + writer = &ICAPXaction_noteCommWroteHeaders; //debug(0,0)("{%s}\n", requestBuf.content()); - comm_old_write_mbuf(connection, &requestBuf, state.isWriting, this); + comm_old_write_mbuf(connection, &requestBuf, writer, this); ICAPXaction_Exit(noteCommConnected); } @@ -231,8 +234,8 @@ { ICAPXaction_Enter(noteCommWroteHeaders); - Must(state.isWriting); - state.isWriting = NULL; + Must(writer); + writer = NULL; Must(status == COMM_OK); writeMoreBody(); @@ -242,7 +245,7 @@ void ICAPXaction::writeMoreBody() { - if (state.isWriting || state.doneWriting) + if (writer || state.doneWriting) return; if (!expectVirginBody()) { @@ -276,8 +279,8 @@ if (writeBuf.hasContent()) { // comm will free the chunk - state.isWriting = &ICAPXaction_noteCommWroteBody; - comm_old_write_mbuf(connection, &writeBuf, state.isWriting, this); + writer = &ICAPXaction_noteCommWroteBody; + comm_old_write_mbuf(connection, &writeBuf, writer, this); } else { writeBuf.clean(); } @@ -301,7 +304,7 @@ { ICAPXaction_Enter(noteCommWroteBody); - state.isWriting = NULL; + writer = NULL; Must(status == COMM_OK); writeMoreBody(); @@ -321,7 +324,7 @@ // unexpected connection close while talking to the ICAP service void ICAPXaction::noteCommClose() { - state.closer = NULL; + closer = NULL; ICAPXaction_Enter(noteCommClose); mustStop(notifyHttp); @@ -341,7 +344,7 @@ void ICAPXaction::startReading() { Must(connection >= 0); - Must(!state.isReading); + Must(!reader); Must(adapted.getRaw()); Must(adapted->data); Must(adapted->data->body); @@ -351,7 +354,7 @@ void ICAPXaction::readMore() { - if (state.isReading || state.doneReading) + if (reader || state.doneReading) return; // do not fill readBuf if we have no space to store the result @@ -360,7 +363,7 @@ // we use the same buffer for headers and body and then consume headers if (readBuf.hasSpace()) { - state.isReading = &ICAPXaction_noteCommRead; + reader = &ICAPXaction_noteCommRead; /* * See comments in ICAPXaction.h about why we use commBuf * here instead of reading directly into readBuf.buf. @@ -370,7 +373,7 @@ commBuf = (char*)memAllocate(MEM_64K_BUF); comm_read(connection, commBuf, readBuf.spaceSize(), - state.isReading, this); + reader, this); } } @@ -379,8 +382,8 @@ { ICAPXaction_Enter(noteCommRead); - Must(state.isReading); - state.isReading = NULL; + Must(reader); + reader = NULL; Must(!state.doneParsing()); Must(status == COMM_OK); @@ -407,7 +410,7 @@ void ICAPXaction::stopReading() { - if (state.isReading) { + if (reader) { // check callback presence because comm module removes // fdc_table[].read.callback after the actual I/O but // before we get the callback via a queued event. @@ -415,9 +418,9 @@ if (comm_has_pending_read(connection) && !comm_has_pending_read_callback(connection)) - comm_read_cancel(connection, state.isReading, this); + comm_read_cancel(connection, reader, this); - state.isReading = NULL; + reader = NULL; } if (commBuf) { Index: squid3/src/ICAPXaction.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPXaction.h,v retrieving revision 1.1.2.17 retrieving revision 1.1.2.18 diff -u -r1.1.2.17 -r1.1.2.18 --- squid3/src/ICAPXaction.h 27 Sep 2005 20:40:57 -0000 1.1.2.17 +++ squid3/src/ICAPXaction.h 29 Sep 2005 05:17:21 -0000 1.1.2.18 @@ -1,6 +1,6 @@ /* - * $Id: ICAPXaction.h,v 1.1.2.17 2005/09/27 20:40:57 dwsquid Exp $ + * $Id: ICAPXaction.h,v 1.1.2.18 2005/09/29 05:17:21 rousskov Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -150,7 +150,13 @@ */ MemBuf readBuf; char *commBuf; - ChunkedCodingParser *bodyParser; + + // active (pending) comm callbacks for the ICAP server connection + IOCB *reader; + CWCB *writer; + PF *closer; + + ChunkedCodingParser *bodyParser; // ICAP response body parser class State { @@ -159,35 +165,32 @@ State(); public: - // XXX: document each unsigned inCall: - 1; + 1; // processing an asynchronous call (e.g., comm read callback) unsigned doneReceiving: - 1; + 1; // expect no new virgin info (from virgin pipe) unsigned doneSending: - 1; + 1; // will not produce new adapted info (for adapted pipe) unsigned doneReading: - 1; + 1; // will not read from the ICAP server connection unsigned doneWriting: - 1; + 1; // will not write to the ICAP server connection + // parsed entire ICAP response from the ICAP server bool doneParsing() const { return parsing == psDone; } + // is parsing ICAP or HTTP headers read from the ICAP server bool parsingHeaders() const { return parsing == psIcapHeader || parsing == psHttpHeader; } - CWCB *isWriting; - IOCB *isReading; - PF *closer; - enum Parsing { psIcapHeader, psHttpHeader, psBody, psDone } parsing; }