--------------------- PatchSet 1642 Date: 2005/09/01 21:00:46 Author: rousskov Branch: squid3-icap Tag: (none) Log: - Do not assume that parsing can suspend only due to lack of input data. Check parser->needsMoreSpace(). If set, we can only hope that the adapted pipe sink will eventually consume more data and free some space. It the sink does not consume, we are stuck. TODO: There should be a timeout in case the sink is broken. The above fix allows us not to limit read size by adapted body buffer space. - Set state.doneSending/Receiving to true in doStop(). This may help catch unexpected callback calls and otherwise wrong states. - Noted that state.doneSending/Receving data members can probably be made into methods because they should always be in sync with this->adapted/virgin pointers Members: src/ICAPXaction.cc:1.1.2.18->1.1.2.19 Index: squid3/src/ICAPXaction.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPXaction.cc,v retrieving revision 1.1.2.18 retrieving revision 1.1.2.19 diff -u -r1.1.2.18 -r1.1.2.19 --- squid3/src/ICAPXaction.cc 1 Sep 2005 18:36:03 -0000 1.1.2.18 +++ squid3/src/ICAPXaction.cc 1 Sep 2005 21:00:46 -0000 1.1.2.19 @@ -18,6 +18,9 @@ // HTTP| --> receive --> encode --> write --> |network // end | <-- send <-- parse <-- read <-- |end +// TODO: state.doneSending/Receving data members should probably be in sync +// with this->adapted/virgin pointers. Make doneSending/Receving methods? + /* comm module handlers (wrappers around corresponding ICAPXaction methods */ // TODO: Teach comm module to call object methods directly @@ -348,9 +351,7 @@ // we use the same buffer for headers and body and then consume headers if (readBuf.hasSpace()) { state.isReading = &ICAPXaction_noteCommRead; - mb_size_t read_sz = XMIN(readBuf.spaceSize(), - adapted->data->body->potentialSpaceSize()); - comm_read(connection, readBuf.space(), read_sz, + comm_read(connection, readBuf.space(), readBuf.spaceSize(), state.isReading, this); } } @@ -481,13 +482,21 @@ debugs(93, 5, "have " << readBuf.contentSize() << " body bytes after " << "parse; parsed all: " << parsed); - if (!parsed) { // needs more data - Must(!state.doneReading); // will get more - Must(readBuf.hasSpace()); // have place for more - return false; + if (parsed) + return true; + + if (bodyParser->needsMoreData()) { + Must(!state.doneReading); // will get more data + Must(readBuf.hasSpace()); // have space for more data } - return true; + if (bodyParser->needsMoreSpace()) { + Must(!state.doneSending); // can hope for more space + Must(adapted->data->body->hasContent()); // paranoid + // TODO: there should be a timeout in case the sink is broken. + } + + return false; } // HTTP side added virgin body data @@ -588,6 +597,8 @@ virgin->sink = NULL; virgin = NULL; // refcounted + + state.doneReceiving = true; } if (adapted != NULL) { @@ -597,6 +608,8 @@ adapted->source = NULL; adapted = NULL; // refcounted + + state.doneSending = true; } if (self != NULL) { // even if notify is notifyNone