]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/BodyPipe.h
Make BodyPipe::MaxCapacity constexpr (#1748)
[thirdparty/squid.git] / src / BodyPipe.h
index f3fdd3d75963bd1cde050938a9ba7d27f812c2b8..e608bd615e8298557f9508f6090d0130a3cdaf3a 100644 (file)
@@ -1,13 +1,13 @@
 /*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
-#ifndef SQUID_BODY_PIPE_H
-#define SQUID_BODY_PIPE_H
+#ifndef SQUID_SRC_BODYPIPE_H
+#define SQUID_SRC_BODYPIPE_H
 
 #include "base/AsyncJob.h"
 #include "base/CbcPointer.h"
@@ -25,13 +25,13 @@ public:
     typedef CbcPointer<BodyProducer> Pointer;
 
     BodyProducer():AsyncJob("BodyProducer") {}
-    virtual ~BodyProducer() {}
+    ~BodyProducer() override {}
 
     virtual void noteMoreBodySpaceAvailable(RefCount<BodyPipe> bp) = 0;
     virtual void noteBodyConsumerAborted(RefCount<BodyPipe> bp) = 0;
 
 protected:
-    void stopProducingFor(RefCount<BodyPipe> &pipe, bool atEof);
+    void stopProducingFor(RefCount<BodyPipe> &, bool atEof);
 };
 
 /** Interface for those who want to consume body content from others.
@@ -45,14 +45,14 @@ public:
     typedef CbcPointer<BodyConsumer> Pointer;
 
     BodyConsumer():AsyncJob("BodyConsumer") {}
-    virtual ~BodyConsumer() {}
+    ~BodyConsumer() override {}
 
     virtual void noteMoreBodyDataAvailable(RefCount<BodyPipe> bp) = 0;
     virtual void noteBodyProductionEnded(RefCount<BodyPipe> bp) = 0;
     virtual void noteBodyProducerAborted(RefCount<BodyPipe> bp) = 0;
 
 protected:
-    void stopConsumingFrom(RefCount<BodyPipe> &pipe);
+    void stopConsumingFrom(RefCount<BodyPipe> &);
 };
 
 /** Makes raw buffer checkin/checkout interface efficient and exception-safe.
@@ -64,13 +64,13 @@ public:
     friend class BodyPipe;
 
 public:
-    BodyPipeCheckout(BodyPipe &pipe); // checks out
+    BodyPipeCheckout(BodyPipe &); // checks out
     ~BodyPipeCheckout(); // aborts checkout unless checkedIn
 
     void checkIn();
 
 public:
-    BodyPipe &pipe;
+    BodyPipe &thePipe;
     MemBuf &buf;
     const uint64_t offset; // of current content, relative to the body start
 
@@ -89,19 +89,21 @@ private:
  */
 class BodyPipe: public RefCountable
 {
+    MEMPROXY_CLASS(BodyPipe);
+
 public:
     typedef RefCount<BodyPipe> Pointer;
     typedef BodyProducer Producer;
     typedef BodyConsumer Consumer;
     typedef BodyPipeCheckout Checkout;
 
-    enum { MaxCapacity = 64*1024 };
+    static constexpr size_t MaxCapacity = 64*1024;
 
     friend class BodyPipeCheckout;
 
 public:
     BodyPipe(Producer *aProducer);
-    ~BodyPipe(); // asserts that producer and consumer are cleared
+    ~BodyPipe() override; // asserts that producer and consumer are cleared
 
     void setBodySize(uint64_t aSize); // set body size
     bool bodySizeKnown() const { return theBodySize >= 0; }
@@ -129,7 +131,7 @@ public:
     bool exhausted() const; // saw eof/abort and all data consumed
     bool stillConsuming(const Consumer::Pointer &consumer) const { return theConsumer == consumer; }
 
-    // start or continue consuming when there is no consumer
+    /// start or continue consuming when producing without consumer
     void enableAutoConsumption();
 
     const MemBuf &buf() const { return theBuf; }
@@ -149,7 +151,7 @@ protected:
     void postConsume(size_t size);
     void postAppend(size_t size);
 
-    void startAutoConsumption(); // delayed start of enabled consumption
+    void startAutoConsumptionIfNeeded();
 
 private:
     int64_t  theBodySize;   // expected total content length, if known
@@ -161,11 +163,10 @@ private:
 
     MemBuf theBuf; // produced but not yet consumed content, if any
 
-    bool mustAutoConsume; // consume when there is no consumer
+    bool mustAutoConsume; ///< keep theBuf empty when producing without consumer
     bool abortedConsumption; ///< called BodyProducer::noteBodyConsumerAborted
     bool isCheckedOut; // to keep track of checkout violations
-
-    CBDATA_CLASS2(BodyPipe);
 };
 
-#endif /* SQUID_BODY_PIPE_H */
+#endif /* SQUID_SRC_BODYPIPE_H */
+