From: Alex Rousskov Date: Thu, 17 Apr 2008 05:44:45 +0000 (-0600) Subject: Fixed and polished autoconsumption mode. X-Git-Tag: SQUID_3_1_0_1~49^2~285 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5121d48e7d8b49f92d44ca7076fc420f1c2c5d1e;p=thirdparty%2Fsquid.git Fixed and polished autoconsumption mode. Fixed: We need to start autoconsuming when new data is appended and we have not started (but enabled autoconsumpiton) before. Polished: When notifying a consumer, checking whether mustAutoConsume is set is pointless as it has no effect on consumer (if any). This check was probably a leftover from pre-BodySink days. --- diff --git a/src/BodyPipe.cc b/src/BodyPipe.cc index 528cf68caa..909c26e704 100644 --- a/src/BodyPipe.cc +++ b/src/BodyPipe.cc @@ -1,6 +1,7 @@ #include "squid.h" #include "BodyPipe.h" +#include "TextException.h" CBDATA_CLASS_INIT(BodyPipe); @@ -284,10 +285,19 @@ void BodyPipe::enableAutoConsumption() { mustAutoConsume = true; debugs(91,5, HERE << "enabled auto consumption" << status()); - if (!theConsumer && theBuf.hasContent()){ - theConsumer = new BodySink; - scheduleBodyDataNotification(); - } + if (!theConsumer && theBuf.hasContent()) + startAutoConsumption(); +} + +// start auto consumption by creating body sink +void +BodyPipe::startAutoConsumption() +{ + Must(mustAutoConsume); + Must(!theConsumer); + theConsumer = new BodySink; + debugs(91,7, HERE << "starting auto consumption" << status()); + scheduleBodyDataNotification(); } MemBuf & @@ -346,6 +356,9 @@ BodyPipe::postAppend(size_t size) { thePutSize += size; debugs(91,7, HERE << "added " << size << " bytes" << status()); + if (mustAutoConsume && !theConsumer && size > 0) + startAutoConsumption(); + // We should not consume here even if mustAutoConsume because the // caller may not be ready for the data to be consumed during this call. scheduleBodyDataNotification(); @@ -358,7 +371,7 @@ BodyPipe::postAppend(size_t size) { void BodyPipe::scheduleBodyDataNotification() { - if (theConsumer || mustAutoConsume) { + if (theConsumer) { AsyncCall::Pointer call = asyncCall(91, 7, "BodyConsumer::noteMoreBodyDataAvailable", BodyConsumerDialer(theConsumer, diff --git a/src/BodyPipe.h b/src/BodyPipe.h index 4a2c58ab54..c56a6cdb11 100644 --- a/src/BodyPipe.h +++ b/src/BodyPipe.h @@ -127,6 +127,8 @@ class BodyPipe: public RefCountable { void postConsume(size_t size); void postAppend(size_t size); + void startAutoConsumption(); // delayed start of enabled consumption + private: int64_t theBodySize; // expected total content length, if known Producer *theProducer; // content producer, if any