]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/BodyPipe.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / BodyPipe.cc
index bdbe3a37a2953ba895d810a901f5563a2cc0b9d2..e8962eb13fc4bf504e7e410f97d34d27b007a16a 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "squid-old.h"
+#include "squid.h"
 #include "base/AsyncJobCalls.h"
 #include "base/TextException.h"
 #include "BodyPipe.h"
@@ -98,7 +98,6 @@ BodyConsumerDialer::canDial(AsyncCall &call)
     return true;
 }
 
-
 /* BodyProducer */
 
 // inform the pipe that we are done and clear the Pointer
@@ -111,8 +110,6 @@ void BodyProducer::stopProducingFor(RefCount<BodyPipe> &pipe, bool atEof)
     pipe = NULL;
 }
 
-
-
 /* BodyConsumer */
 
 // inform the pipe that we are done and clear the Pointer
@@ -124,7 +121,6 @@ void BodyConsumer::stopConsumingFrom(RefCount<BodyPipe> &pipe)
     pipe = NULL;
 }
 
-
 /* BodyPipe */
 
 BodyPipe::BodyPipe(Producer *aProducer): theBodySize(-1),
@@ -268,14 +264,28 @@ BodyPipe::clearConsumer()
 void
 BodyPipe::expectNoConsumption()
 {
-    Must(!theConsumer);
+    // We may be called multiple times because multiple jobs on the consumption
+    // chain may realize that there will be no more setConsumer() calls (e.g.,
+    // consuming code and retrying code). It is both difficult and not really
+    // necessary for them to coordinate their expectNoConsumption() calls.
+
+    // As a consequence, we may be called when we are auto-consuming already.
+
     if (!abortedConsumption && !exhausted()) {
+        // Before we abort, any regular consumption should be over and auto
+        // consumption must not be started.
+        Must(!theConsumer);
+
         AsyncCall::Pointer call= asyncCall(91, 7,
                                            "BodyProducer::noteBodyConsumerAborted",
                                            BodyProducerDialer(theProducer,
                                                               &BodyProducer::noteBodyConsumerAborted, this));
         ScheduleCallHere(call);
         abortedConsumption = true;
+
+        // in case somebody enabled auto-consumption before regular one aborted
+        if (mustAutoConsume)
+            startAutoConsumption();
     }
 }
 
@@ -392,7 +402,6 @@ BodyPipe::postAppend(size_t size)
         clearProducer(true); // reached end-of-body
 }
 
-
 void
 BodyPipe::scheduleBodyDataNotification()
 {
@@ -433,9 +442,9 @@ const char *BodyPipe::status() const
 
     outputBuffer.append(" [", 2);
 
-    outputBuffer.Printf("%"PRIu64"<=%"PRIu64, theGetSize, thePutSize);
+    outputBuffer.Printf("%" PRIu64 "<=%" PRIu64, theGetSize, thePutSize);
     if (theBodySize >= 0)
-        outputBuffer.Printf("<=%"PRId64, theBodySize);
+        outputBuffer.Printf("<=%" PRId64, theBodySize);
     else
         outputBuffer.append("<=?", 3);
 
@@ -461,7 +470,6 @@ const char *BodyPipe::status() const
     return outputBuffer.content();
 }
 
-
 /* BodyPipeCheckout */
 
 BodyPipeCheckout::BodyPipeCheckout(BodyPipe &aPipe): pipe(aPipe),
@@ -489,7 +497,6 @@ BodyPipeCheckout::checkIn()
     checkedIn = true;
 }
 
-
 BodyPipeCheckout::BodyPipeCheckout(const BodyPipeCheckout &c): pipe(c.pipe),
         buf(c.buf), offset(c.offset), checkedOutSize(c.checkedOutSize),
         checkedIn(c.checkedIn)