]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed and polished autoconsumption mode.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 17 Apr 2008 05:44:45 +0000 (23:44 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 17 Apr 2008 05:44:45 +0000 (23:44 -0600)
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.

src/BodyPipe.cc
src/BodyPipe.h

index 528cf68caa3d5d57313415addc783dcc095d0e47..909c26e704fd962bc2345c32f86d90d0d006ae9a 100644 (file)
@@ -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,
index 4a2c58ab54bcfcecc1399828e41ac13993c7e52d..c56a6cdb112bda0bebc8e76ad578b79d433728b5 100644 (file)
@@ -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