]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/delay_pools.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / delay_pools.cc
index 73913fa0ecb140dbac76f33cf88847e064e5dd29..1306527f5664c85f8b30dee01f393ac283bf0c96 100644 (file)
@@ -1,82 +1,52 @@
 /*
- * DEBUG: section 77    Delay Pools
- * AUTHOR: Robert Collins <robertc@squid-cache.org>
- * Based upon original delay pools code by
- *   David Luyer <david@luyer.net>
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 77    Delay Pools */
+
 /**
  \defgroup DelayPoolsInternal Delay Pools Internal
  \ingroup DelayPoolsAPI
  */
 
-#include "config.h"
-
-#if DELAY_POOLS
 #include "squid.h"
-#include "CacheManager.h"
-#include "DelaySpec.h"
-#include "DelayPools.h"
-#include "event.h"
-#include "StoreClient.h"
-#include "Store.h"
-#include "MemObject.h"
+
+#if USE_DELAY_POOLS
 #include "client_side_request.h"
-#include "ConfigParser.h"
-#include "DelayId.h"
-#include "Array.h"
-#include "SquidString.h"
-#include "SquidTime.h"
+#include "comm/Connection.h"
 #include "CommonPool.h"
 #include "CompositePoolNode.h"
-#include "DelayPool.h"
-#include "DelayVector.h"
-#include "NullDelayId.h"
+#include "ConfigParser.h"
 #include "DelayBucket.h"
-#include "DelayUser.h"
+#include "DelayId.h"
+#include "DelayPool.h"
+#include "DelayPools.h"
+#include "DelaySpec.h"
 #include "DelayTagged.h"
+#include "DelayUser.h"
+#include "DelayVector.h"
+#include "event.h"
+#include "http/Stream.h"
 #include "ip/Address.h"
-
-/// \ingroup DelayPoolsInternal
-long DelayPools::MemoryUsed = 0;
+#include "MemObject.h"
+#include "mgr/Registration.h"
+#include "NullDelayId.h"
+#include "SquidString.h"
+#include "SquidTime.h"
+#include "Store.h"
+#include "StoreClient.h"
 
 /// \ingroup DelayPoolsInternal
 class Aggregate : public CompositePoolNode
 {
+    MEMPROXY_CLASS(Aggregate);
 
 public:
     typedef RefCount<Aggregate> Pointer;
-    void *operator new(size_t);
-    void operator delete (void *);
     Aggregate();
     ~Aggregate();
     virtual DelaySpec *rate() {return &spec;}
@@ -95,10 +65,9 @@ private:
     /// \ingroup DelayPoolsInternal
     class AggregateId:public DelayIdComposite
     {
+        MEMPROXY_CLASS(Aggregate::AggregateId);
 
     public:
-        void *operator new(size_t);
-        void operator delete (void *);
         AggregateId (RefCount<Aggregate>);
         virtual int bytesWanted (int min, int max) const;
         virtual void bytesIn(int qty);
@@ -138,6 +107,7 @@ private:
 /// \ingroup DelayPoolsInternal
 class VectorPool : public CompositePoolNode
 {
+    MEMPROXY_CLASS(VectorPool);
 
 public:
     typedef RefCount<VectorPool> Pointer;
@@ -166,10 +136,9 @@ protected:
     /// \ingroup DelayPoolsInternal
     class Id:public DelayIdComposite
     {
+        MEMPROXY_CLASS(VectorPool::Id);
 
     public:
-        void *operator new(size_t);
-        void operator delete (void *);
         Id (RefCount<VectorPool>, int);
         virtual int bytesWanted (int min, int max) const;
         virtual void bytesIn(int qty);
@@ -183,10 +152,7 @@ protected:
 /// \ingroup DelayPoolsInternal
 class IndividualPool : public VectorPool
 {
-
-public:
-    void *operator new(size_t);
-    void operator delete(void *);
+    MEMPROXY_CLASS(IndividualPool);
 
 protected:
     virtual char const *label() const {return "Individual";}
@@ -196,10 +162,7 @@ protected:
 /// \ingroup DelayPoolsInternal
 class ClassCNetPool : public VectorPool
 {
-
-public:
-    void *operator new(size_t);
-    void operator delete (void *);
+    MEMPROXY_CLASS(ClassCNetPool);
 
 protected:
     virtual char const *label() const {return "Network";}
@@ -227,6 +190,7 @@ public:
 /// \ingroup DelayPoolsInternal
 class ClassCHostPool : public CompositePoolNode
 {
+    MEMPROXY_CLASS(ClassCHostPool);
 
 public:
     typedef RefCount<ClassCHostPool> Pointer;
@@ -261,10 +225,9 @@ protected:
     /// \ingroup DelayPoolsInternal
     class Id:public DelayIdComposite
     {
+        MEMPROXY_CLASS(ClassCHostPool::Id);
 
     public:
-        void *operator new(size_t);
-        void operator delete (void *);
         Id (RefCount<ClassCHostPool>, unsigned char, unsigned char);
         virtual int bytesWanted (int min, int max) const;
         virtual void bytesIn(int qty);
@@ -282,20 +245,6 @@ Aggregate::AggregateId::delayRead(DeferredRead const &aRead)
     theAggregate->delayRead(aRead);
 }
 
-void *
-CommonPool::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (CommonPool);
-    return ::operator new (size);
-}
-
-void
-CommonPool::operator delete(void *address)
-{
-    DelayPools::MemoryUsed -= sizeof(CommonPool);
-    ::operator delete(address);
-}
-
 CommonPool *
 CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeCopy)
 {
@@ -340,7 +289,9 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new Aggregate);
             temp->push_back (new ClassCNetPool);
             temp->push_back (new ClassCHostPool);
+#if USE_AUTH
             temp->push_back (new DelayUser);
+#endif
         }
         break;
 
@@ -366,7 +317,7 @@ ClassCBucket::update (DelaySpec const &rate, int incr)
     /* If we aren't active, don't try to update us ! */
     assert (rate.restore_bps != -1);
 
-    for (unsigned char j = 0; j < individuals.size(); ++j)
+    for (unsigned int j = 0; j < individuals.size(); ++j)
         individuals.values[j].update (rate, incr);
 }
 
@@ -424,34 +375,6 @@ ClassCBucket::initHostIndex (DelaySpec &rate, unsigned char index, unsigned char
     individuals.values[newIndex].init (rate);
 }
 
-void *
-CompositePoolNode::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (CompositePoolNode);
-    return ::operator new (size);
-}
-
-void
-CompositePoolNode::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (CompositePoolNode);
-    ::operator delete (address);
-}
-
-void *
-Aggregate::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (Aggregate);
-    return ::operator new (size);
-}
-
-void
-Aggregate::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (Aggregate);
-    ::operator delete (address);
-}
-
 Aggregate::Aggregate()
 {
     theBucket.init (*rate());
@@ -506,20 +429,6 @@ Aggregate::id(CompositeSelectionDetails &details)
         return new NullDelayId;
 }
 
-void *
-Aggregate::AggregateId::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (AggregateId);
-    return ::operator new (size);
-}
-
-void
-Aggregate::AggregateId::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (AggregateId);
-    ::operator delete (address);
-}
-
 Aggregate::AggregateId::AggregateId(RefCount<Aggregate> anAggregate) : theAggregate(anAggregate)
 {}
 
@@ -543,8 +452,7 @@ unsigned short DelayPools::pools_ (0);
 void
 DelayPools::RegisterWithCacheManager(void)
 {
-    CacheManager::GetInstance()->
-    registerAction("delay", "Delay Pool Levels", Stats, 0, 1);
+    Mgr::RegisterAction("delay", "Delay Pool Levels", Stats, 0, 1);
 }
 
 void
@@ -554,7 +462,6 @@ DelayPools::Init()
     RegisterWithCacheManager();
 }
 
-
 void
 DelayPools::InitDelayData()
 {
@@ -563,8 +470,6 @@ DelayPools::InitDelayData()
 
     DelayPools::delay_data = new DelayPool[pools()];
 
-    DelayPools::MemoryUsed += pools() * sizeof(DelayPool);
-
     eventAdd("DelayPools::Update", DelayPools::Update, NULL, 1.0, 1);
 }
 
@@ -573,7 +478,6 @@ DelayPools::FreeDelayData()
 {
     eventDelete(DelayPools::Update, NULL);
     delete[] DelayPools::delay_data;
-    DelayPools::MemoryUsed -= pools() * sizeof(*DelayPools::delay_data);
     pools_ = 0;
 }
 
@@ -592,7 +496,7 @@ DelayPools::Update(void *unused)
 
     LastUpdate = squid_curtime;
 
-    Vector<Updateable *>::iterator pos = toUpdate.begin();
+    std::vector<Updateable *>::iterator pos = toUpdate.begin();
 
     while (pos != toUpdate.end()) {
         (*pos)->update(incr);
@@ -610,7 +514,7 @@ DelayPools::registerForUpdates(Updateable *anObject)
 void
 DelayPools::deregisterForUpdates (Updateable *anObject)
 {
-    Vector<Updateable *>::iterator pos = toUpdate.begin();
+    std::vector<Updateable *>::iterator pos = toUpdate.begin();
 
     while (pos != toUpdate.end() && *pos != anObject) {
         ++pos;
@@ -618,7 +522,7 @@ DelayPools::deregisterForUpdates (Updateable *anObject)
 
     if (pos != toUpdate.end()) {
         /* move all objects down one */
-        Vector<Updateable *>::iterator temp = pos;
+        std::vector<Updateable *>::iterator temp = pos;
         ++pos;
 
         while (pos != toUpdate.end()) {
@@ -631,24 +535,20 @@ DelayPools::deregisterForUpdates (Updateable *anObject)
     }
 }
 
-Vector<Updateable *> DelayPools::toUpdate;
+std::vector<Updateable *> DelayPools::toUpdate;
 
 void
 DelayPools::Stats(StoreEntry * sentry)
 {
-    unsigned short i;
-
     storeAppendPrintf(sentry, "Delay pools configured: %d\n\n", DelayPools::pools());
 
-    for (i = 0; i < DelayPools::pools(); ++i) {
+    for (unsigned short i = 0; i < DelayPools::pools(); ++i) {
         if (DelayPools::delay_data[i].theComposite().getRaw()) {
             storeAppendPrintf(sentry, "Pool: %d\n\tClass: %s\n\n", i + 1, DelayPools::delay_data[i].pool->theClassTypeLabel());
             DelayPools::delay_data[i].theComposite()->stats (sentry);
         } else
             storeAppendPrintf(sentry, "\tMisconfigured pool.\n\n");
     }
-
-    storeAppendPrintf(sentry, "Memory Used: %d bytes\n", (int) DelayPools::MemoryUsed);
 }
 
 void
@@ -667,10 +567,10 @@ DelayPools::pools()
 }
 
 void
-DelayPools::pools (u_short newPools)
+DelayPools::pools(unsigned short newPools)
 {
     if (pools()) {
-        debugs(3, 0, "parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config");
+        debugs(3, DBG_CRITICAL, "parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config");
         FreePools();
     }
 
@@ -705,20 +605,6 @@ VectorMap<Key,Value>::insert (Key const key)
     return index;
 }
 
-void *
-IndividualPool::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (IndividualPool);
-    return ::operator new (size);
-}
-
-void
-IndividualPool::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (IndividualPool);
-    ::operator delete (address);
-}
-
 VectorPool::VectorPool()
 {
     DelayPools::registerForUpdates (this);
@@ -741,7 +627,7 @@ VectorPool::stats(StoreEntry * sentry)
 
     storeAppendPrintf(sentry, "\t\tCurrent:");
 
-    for (unsigned int i = 0; i < buckets.size(); i++) {
+    for (unsigned int i = 0; i < buckets.size(); ++i) {
         storeAppendPrintf(sentry, " %d:", buckets.key_map[i]);
         buckets.values[i].stats(sentry);
     }
@@ -810,7 +696,7 @@ VectorPool::id(CompositeSelectionDetails &details)
         return new NullDelayId;
 
     /* non-IPv4 are not able to provide IPv4-bitmask for this pool type key. */
-    if ( !details.src_addr.IsIPv4() )
+    if ( !details.src_addr.isIPv4() )
         return new NullDelayId;
 
     unsigned int key = makeKey(details.src_addr);
@@ -825,20 +711,6 @@ VectorPool::id(CompositeSelectionDetails &details)
     return new Id(this, resultIndex);
 }
 
-void *
-VectorPool::Id::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (Id);
-    return ::operator new (size);
-}
-
-void
-VectorPool::Id::operator delete(void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (Id);
-    ::operator delete (address);
-}
-
 VectorPool::Id::Id(VectorPool::Pointer aPool, int anIndex) : theVector (aPool), theIndex (anIndex)
 {}
 
@@ -858,41 +730,26 @@ unsigned int
 IndividualPool::makeKey(Ip::Address &src_addr) const
 {
     /* IPv4 required for this pool */
-    if ( !src_addr.IsIPv4() )
+    if ( !src_addr.isIPv4() )
         return 1;
 
     struct in_addr host;
-    src_addr.GetInAddr(host);
+    src_addr.getInAddr(host);
     return (ntohl(host.s_addr) & 0xff);
 }
 
-void *
-ClassCNetPool::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (ClassCNetPool);
-    return ::operator new (size);
-}
-
-void
-ClassCNetPool::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (ClassCNetPool);
-    ::operator delete (address);
-}
-
 unsigned int
 ClassCNetPool::makeKey(Ip::Address &src_addr) const
 {
     /* IPv4 required for this pool */
-    if ( !src_addr.IsIPv4() )
+    if ( !src_addr.isIPv4() )
         return 1;
 
     struct in_addr net;
-    src_addr.GetInAddr(net);
+    src_addr.getInAddr(net);
     return ( (ntohl(net.s_addr) >> 8) & 0xff);
 }
 
-
 ClassCHostPool::ClassCHostPool()
 {
     DelayPools::registerForUpdates (this);
@@ -957,12 +814,12 @@ unsigned char
 ClassCHostPool::makeHostKey(Ip::Address &src_addr) const
 {
     /* IPv4 required for this pool */
-    if ( !src_addr.IsIPv4() )
+    if ( !src_addr.isIPv4() )
         return 1;
 
     /* Temporary bypass for IPv4-only */
     struct in_addr host;
-    src_addr.GetInAddr(host);
+    src_addr.getInAddr(host);
     return (ntohl(host.s_addr) & 0xff);
 }
 
@@ -970,11 +827,11 @@ unsigned int
 ClassCHostPool::makeKey(Ip::Address &src_addr) const
 {
     /* IPv4 required for this pool */
-    if ( !src_addr.IsIPv4() )
+    if ( !src_addr.isIPv4() )
         return 1;
 
     struct in_addr net;
-    src_addr.GetInAddr(net);
+    src_addr.getInAddr(net);
     return ( (ntohl(net.s_addr) >> 8) & 0xff);
 }
 
@@ -985,7 +842,7 @@ ClassCHostPool::id(CompositeSelectionDetails &details)
         return new NullDelayId;
 
     /* non-IPv4 are not able to provide IPv4-bitmask for this pool type key. */
-    if ( !details.src_addr.IsIPv4() )
+    if ( !details.src_addr.isIPv4() )
         return new NullDelayId;
 
     unsigned int key = makeKey (details.src_addr);
@@ -1006,20 +863,6 @@ ClassCHostPool::id(CompositeSelectionDetails &details)
     return new Id (this, netIndex, hostIndex);
 }
 
-void *
-ClassCHostPool::Id::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (Id);
-    return ::operator new (size);
-}
-
-void
-ClassCHostPool::Id::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (Id);
-    ::operator delete (address);
-}
-
 ClassCHostPool::Id::Id (ClassCHostPool::Pointer aPool, unsigned char aNet, unsigned char aHost) : theClassCHost (aPool), theNet (aNet), theHost (aHost)
 {}
 
@@ -1035,5 +878,5 @@ ClassCHostPool::Id::bytesIn(int qty)
     theClassCHost->buckets.values[theNet].individuals.values[theHost].bytesIn (qty);
 }
 
-#endif
+#endif /* USE_DELAY_POOLS */