]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: Merge String loss fix.
authorrobertc <>
Thu, 6 Mar 2003 18:51:55 +0000 (18:51 +0000)
committerrobertc <>
Thu, 6 Mar 2003 18:51:55 +0000 (18:51 +0000)
Keywords:

Patches applied:

  * robertc@squid-cache.org--squid/squid--comms--3.0--patch-10
     Track all created strings.

  * robertc@squid-cache.org--squid/squid--comms--3.0--patch-9
     More tuning.

21 files changed:
include/splay.h
src/DelayUser.h
src/DelayVector.h
src/HttpHdrExtField.cc
src/HttpHeader.cc
src/HttpHeaderRange.h
src/HttpHeaderTools.cc
src/HttpReply.cc
src/SquidString.h
src/String.cc
src/String.cci
src/client_side_reply.cc
src/delay_pools.cc
src/enums.h
src/ftp.cc
src/mem.cc
src/net_db.cc
src/peer_digest.cc
src/protos.h
src/structs.h
src/typedefs.h

index d9d15ba7506c46ad79b9244599965505752f7d69..f606e8121ec5a33c3b8bd1b2f5ed87b57b607b48 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: splay.h,v 1.17 2003/03/04 01:40:22 robertc Exp $
+ * $Id: splay.h,v 1.18 2003/03/06 11:51:55 robertc Exp $
  */
 
 #ifndef SQUID_SPLAY_H
@@ -51,9 +51,12 @@ class Splay {
   public:
     typedef V Value;
     typedef int SPLAYCMP(Value const &a, Value const &b);
-    Splay():head(NULL){}
+    Splay():head(NULL), elements (0){}
     mutable SplayNode<V> * head;
     Value const *find (Value const &, SPLAYCMP *compare) const;
+    void insert(Value const &, SPLAYCMP *compare);
+    void remove(Value const &, SPLAYCMP *compare);
+    size_t elements;
 };
 
 
@@ -124,6 +127,7 @@ SplayNode<V>::insert(Value data, SPLAYCMP * compare)
     SplayNode<V> *newNode = new SplayNode<V>;
     newNode->data = data;
     if (this == NULL) {
+       splayLastResult = -1;
        newNode->left = newNode->right = NULL;
        return newNode;
     }
@@ -214,6 +218,24 @@ Splay<V>::find (Value const &value, SPLAYCMP *compare) const
     return &head->data;
 }
 
+template <class V>
+void
+Splay<V>::insert(Value const &value, SPLAYCMP *compare)
+{
+    assert (!find (value, compare));
+    head = head->insert(value, compare);
+    ++elements;
+}
+
+template <class V>
+void
+Splay<V>::remove(Value const &value, SPLAYCMP *compare)
+{
+    assert (find (value, compare));
+    head = head->remove(value, compare);
+    --elements;
+}
+
 #endif
 
 #endif /* SQUID_SPLAY_H */
index 0ebfb6e3dbdb795c7c0a18f409c1c763a3325d0f..9973467e1bc3c8182ecdb655d5bf59b3e635af00 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: DelayUser.h,v 1.3 2003/02/21 22:50:05 robertc Exp $
+ * $Id: DelayUser.h,v 1.4 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 77    Delay Pools
  * AUTHOR: Robert Collins <robertc@squid-cache.org>
@@ -101,6 +101,8 @@ class Id:public DelayIdComposite
         DelayUserBucket::Pointer theBucket;
     };
 
+    friend class Id;
+
     DelaySpec spec;
     Splay<DelayUserBucket::Pointer> buckets;
 };
index 22c0f4b058af0e5d8200655c2749ea8a2956ff1f..5dc21a84c2912eb263ee87cf91ea0fd18e17a1ad 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: DelayVector.h,v 1.4 2003/03/04 01:40:25 robertc Exp $
+ * $Id: DelayVector.h,v 1.5 2003/03/06 11:51:55 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -78,6 +78,8 @@ class Id:public DelayIdComposite
         typedef Vector<DelayIdComposite::Pointer>::const_iterator const_iterator;
     };
 
+    friend class Id;
+
     Vector<CompositePoolNode::Pointer> pools;
     typedef Vector<CompositePoolNode::Pointer>::iterator iterator;
     typedef Vector<CompositePoolNode::Pointer>::const_iterator const_iterator;
index ba25aa363964b556d2fc45ba2408d9f6440bf84c..b4fbd38382d1a75cc0254818860e162ca671ee9f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHdrExtField.cc,v 1.11 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpHdrExtField.cc,v 1.12 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 69    HTTP Header: Extension Field
  * AUTHOR: Alex Rousskov
@@ -45,7 +45,7 @@ static HttpHdrExtField *
 httpHdrExtFieldDoCreate(const char *name, int name_len,
                         const char *value, int value_len)
 {
-    HttpHdrExtField *f = xcalloc(1, sizeof(HttpHdrExtField));
+    HttpHdrExtField *f = new HttpHdrExtField;
     stringLimitInit(&f->name, name, name_len);
     stringLimitInit(&f->value, value, value_len);
     return f;
@@ -88,7 +88,7 @@ httpHdrExtFieldDestroy(HttpHdrExtField * f)
     assert(f);
     f->name.clean();
     f->value.clean();
-    xfree(f);
+    delete f;
 }
 
 HttpHdrExtField *
index e0ea9586a150df7874f6893bed85995f63541b4d..20b678f24b8cec735320303d5cf07bb5d6e495b1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeader.cc,v 1.86 2003/03/06 06:21:36 robertc Exp $
+ * $Id: HttpHeader.cc,v 1.87 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 55    HTTP Header
  * AUTHOR: Alex Rousskov
@@ -1121,7 +1121,7 @@ httpHeaderEntryCreate(http_hdr_type id, const char *name, const char *value)
 {
     HttpHeaderEntry *e;
     assert_eid(id);
-    e = (HttpHeaderEntry *)memAllocate(MEM_HTTP_HDR_ENTRY);
+    e = new HttpHeaderEntry;
     e->id = id;
 
     if (id != HDR_OTHER)
@@ -1157,7 +1157,7 @@ httpHeaderEntryDestroy(HttpHeaderEntry * e)
 
     e->id = HDR_BAD_HDR;
 
-    memFree(e, MEM_HTTP_HDR_ENTRY);
+    delete e;
 }
 
 /* parses and inits header entry, returns new entry on success */
@@ -1186,7 +1186,7 @@ httpHeaderEntryParseCreate(const char *field_start, const char *field_end)
     }
 
     /* now we know we can parse it */
-    e = (HttpHeaderEntry *)memAllocate(MEM_HTTP_HDR_ENTRY);
+    e = new HttpHeaderEntry;
 
     debug(55, 9) ("creating entry %p: near '%s'\n", e, getStringPrefix(field_start, field_end));
 
@@ -1218,7 +1218,7 @@ httpHeaderEntryParseCreate(const char *field_start, const char *field_end)
         if (e->id == HDR_OTHER)
             e->name.clean();
 
-        memFree(e, MEM_HTTP_HDR_ENTRY);
+        delete e;
 
         return NULL;
     }
@@ -1398,3 +1398,22 @@ httpHeaderNameById(int id)
 
     return HeadersAttrs[id].name;
 }
+
+MemPool *HttpHeaderEntry::Pool(NULL);
+void *
+HttpHeaderEntry::operator new (size_t byteCount)
+{
+    /* derived classes with different sizes must implement their own new */
+    assert (byteCount == sizeof (HttpHeaderEntry));
+
+    if (!Pool)
+        Pool = memPoolCreate("HttpHeaderEntry", sizeof (HttpHeaderEntry));
+
+    return memPoolAlloc(Pool);
+}
+
+void
+HttpHeaderEntry::operator delete (void *address)
+{
+    memPoolFree (Pool, address);
+}
index e9e05e81955a2ece46b0e2758842e9a7f46361c0..db7290060459d2921101acbb7d32ad7243d148b4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeaderRange.h,v 1.2 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpHeaderRange.h,v 1.3 2003/03/06 11:51:55 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -36,7 +36,7 @@
 
 #include "Range.h"
 
-typedef struct _HttpReply HttpReply;
+class HttpReply;
 /* http byte-range-spec */
 
 class HttpHdrRangeSpec
index 5a2897a865d2a1928a80d400b0bb4d2a0b32c79d..9b5aea92ae2e71513c97262e8d7181bf38e85b0e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeaderTools.cc,v 1.39 2003/03/06 06:21:37 robertc Exp $
+ * $Id: HttpHeaderTools.cc,v 1.40 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 66    HTTP Header Tools
  * AUTHOR: Alex Rousskov
@@ -52,7 +52,7 @@ httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count)
     assert(attrs && count);
 
     /* allocate space */
-    table = (HttpHeaderFieldInfo *)xcalloc(count, sizeof(HttpHeaderFieldInfo));
+    table = new HttpHeaderFieldInfo[count];
 
     for (i = 0; i < count; ++i) {
         const http_hdr_type id = attrs[i].id;
@@ -60,14 +60,12 @@ httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count)
         /* sanity checks */
         assert(id >= 0 && id < count);
         assert(attrs[i].name);
-        assert(info->id == 0 && info->type == 0);      /* was not set before */
+        assert(info->id == HDR_ACCEPT && info->type == ftInvalid);     /* was not set before */
         /* copy and init fields */
         info->id = id;
         info->type = attrs[i].type;
         info->name = attrs[i].name;
         assert(info->name.size());
-        /* init stats */
-        memset(&info->stat, 0, sizeof(info->stat));
     }
 
     return table;
@@ -81,7 +79,7 @@ httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo * table, int count)
     for (i = 0; i < count; ++i)
         table[i].name.clean();
 
-    xfree(table);
+    delete table;
 }
 
 void
index 497d9435d5fdfe9cacf7a313927396f2bed65bae..2e1629c5c91f5f42566e9b404914d40f6428196d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpReply.cc,v 1.55 2003/03/06 06:21:37 robertc Exp $
+ * $Id: HttpReply.cc,v 1.56 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 58    HTTP Reply (Response)
  * AUTHOR: Alex Rousskov
@@ -82,7 +82,7 @@ httpReplyInitModule(void)
 HttpReply *
 httpReplyCreate(void)
 {
-    HttpReply *rep = (HttpReply *)memAllocate(MEM_HTTP_REPLY);
+    HttpReply *rep = new HttpReply;
     debug(58, 7) ("creating rep: %p\n", rep);
     httpReplyInit(rep);
     return rep;
@@ -392,7 +392,7 @@ httpReplyUpdateOnNotModified(HttpReply * rep, HttpReply const * freshRep)
 static void
 httpReplyDoDestroy(HttpReply * rep)
 {
-    memFree(rep, MEM_HTTP_REPLY);
+    delete rep;
 }
 
 static time_t
@@ -621,3 +621,22 @@ httpReplyBodyBuildSize(request_t * request, HttpReply * reply, dlink_list * body
         delete checklist;
     }
 }
+
+MemPool *HttpReply::Pool(NULL);
+void *
+HttpReply::operator new (size_t byteCount)
+{
+    /* derived classes with different sizes must implement their own new */
+    assert (byteCount == sizeof (HttpReply));
+
+    if (!Pool)
+        Pool = memPoolCreate("HttpReply", sizeof (HttpReply));
+
+    return memPoolAlloc(Pool);
+}
+
+void
+HttpReply::operator delete (void *address)
+{
+    memPoolFree (Pool, address);
+}
index a0bf3eab223bbf8010111016bec378461a817cf9..167fa68dbaa6b288e06ae738cad9a9068ddf2098 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: SquidString.h,v 1.3 2003/03/06 06:21:37 robertc Exp $
+ * $Id: SquidString.h,v 1.4 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
 #ifndef SQUID_STRING_H
 #define SQUID_STRING_H
 
+#define DEBUGSTRINGS 0
+#if DEBUGSTRINGS
+#include "splay.h"
+
+class String;
+
+class StringRegistry
+{
+
+public:
+    StringRegistry() : registered(false) {}
+
+    static StringRegistry &Instance();
+
+    void add
+        (String const *);
+
+    void remove
+        (String const *);
+
+private:
+    static OBJH Stat;
+
+    static StringRegistry Instance_;
+
+    static SplayNode<String const *>::SPLAYWALKEE Stater;
+
+    Splay<String const *> entries;
+
+    bool registered;
+
+    void registerMe();
+};
+
+class StoreEntry;
+#endif
+
 class String
 {
 
@@ -75,6 +112,12 @@ public:
 
     _SQUID_INLINE_ void cutPointer (char const *loc);
 
+#if DEBUGSTRINGS
+
+    void stat (StoreEntry *) const;
+
+#endif
+
 private:
     /* never reference these directly! */
     unsigned short int size_;  /* buffer size; 64K limit */
index a962c703e2d019b001bd5780fdf48b2e31784cb3..93140f85156fcb57e56db3b297990c56e5904397 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: String.cc,v 1.14 2003/03/06 06:21:37 robertc Exp $
+ * $Id: String.cc,v 1.15 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
  */
 
 #include "squid.h"
+#include "Store.h"
 
 void
 String::initBuf(size_t sz)
 {
-    buf_ = (char *)memAllocString(sz, &sz);
+    buf((char *)memAllocString(sz, &sz));
     assert(sz < 65536);
     size_ = sz;
 }
@@ -57,6 +58,7 @@ String::init(char const *str)
 String::String (char const *aString) : size_(0), len_(0), buf_(NULL)
 {
     init (aString);
+    StringRegistry::Instance().add(this);
 }
 
 String &
@@ -73,7 +75,7 @@ String::operator = (String const &old)
     clean ();
 
     if (old.len_)
-        limitInit (old.buf_, old.len_);
+        limitInit (old.buf(), old.len_);
 
     return *this;
 }
@@ -90,7 +92,8 @@ String::limitInit(const char *str, int len)
 
 String::String (String const &old) : size_(0), len_(0), buf_(NULL)
 {
-    init (old.buf_);
+    init (old.buf());
+    StringRegistry::Instance().add(this);
 }
 
 void
@@ -98,7 +101,7 @@ String::clean()
 {
     assert(this);
 
-    if (buf_)
+    if (buf())
         memFreeString(size_, buf_);
 
     len_ = 0;
@@ -111,6 +114,7 @@ String::clean()
 String::~String()
 {
     clean();
+    StringRegistry::Instance().remove(this);
 }
 
 void
@@ -135,7 +139,7 @@ String::append(const char *str, int len)
         snew.initBuf(snew.len_ + 1);
 
         if (buf_)
-            xmemcpy(snew.buf_, buf_, len_);
+            xmemcpy(snew.buf_, buf(), len_);
 
         if (len)
             xmemcpy(snew.buf_ + len_, str, len);
@@ -156,7 +160,7 @@ String::append(char const *str)
 void
 String::append(String const &old)
 {
-    append (old.buf_, old.len_);
+    append (old.buf(), old.len_);
 }
 
 void
@@ -164,7 +168,7 @@ String::absorb(String &old)
 {
     clean();
     size_ = old.size_;
-    buf_ = old.buf_;
+    buf (old.buf_);
     len_ = old.len_;
     old.size_ = 0;
     old.buf_ = NULL;
@@ -178,6 +182,73 @@ String::buf(char *newBuf)
     buf_ = newBuf;
 }
 
+#if DEBUGSTRINGS
+void
+String::stat(StoreEntry *entry) const
+{
+    storeAppendPrintf(entry, "%p : %d/%d \"%s\"\n",this,len_, size_, buf());
+}
+
+StringRegistry &
+StringRegistry::Instance()
+{
+    return Instance_;
+}
+
+template <class C>
+int
+ptrcmp(C const &lhs, C const &rhs)
+{
+    return lhs - rhs;
+}
+
+void
+StringRegistry::registerMe()
+{
+    registered = true;
+    cachemgrRegister("strings",
+                     "Strings in use in squid", Stat, 0, 1);
+}
+
+void
+
+StringRegistry::add
+    (String const *entry)
+{
+    if (!registered)
+        registerMe();
+
+    entries.insert(entry, ptrcmp);
+}
+
+void
+
+StringRegistry::remove
+    (String const *entry)
+{
+    entries.remove(entry, ptrcmp);
+}
+
+StringRegistry StringRegistry::Instance_;
+
+extern size_t memStringCount();
+
+void
+StringRegistry::Stat(StoreEntry *entry)
+{
+    storeAppendPrintf(entry, "%lu entries, %lu reported from MemPool\n", (unsigned long) Instance().entries.elements, (unsigned long) memStringCount());
+    Instance().entries.head->walk(Stater, entry);
+}
+
+void
+StringRegistry::Stater(String const * const & nodedata, void *state)
+{
+    StoreEntry *entry = (StoreEntry *) state;
+    nodedata->stat(entry);
+}
+
+#endif
+
 #ifndef _USE_INLINE_
 #include "String.cci"
 #endif
index 878451858210bb424c26f38c62052c04d41ba96d..045821c5e6079a14aefe65345fd7fdd9630c7aef 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: String.cci,v 1.2 2003/03/06 06:21:37 robertc Exp $
+ * $Id: String.cci,v 1.3 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
  */
 
 String::String() : size_(0), len_(0), buf_ (NULL)
-{}
+{
+#if DEBUGSTRINGS
+    StringRegistry::Instance().add(this);
+#endif
+}
 
 int
 String::size() const
index cefa29be701e501ba9bbda6b67122044fcee1596..699b94cc594debe482e5eaa891820772b9793ac1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_reply.cc,v 1.43 2003/03/04 01:40:26 robertc Exp $
+ * $Id: client_side_reply.cc,v 1.44 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 88    Client-side Reply Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -1233,7 +1233,7 @@ clientReplyContext::storeNotOKTransferDone() const
     assert(mem != NULL);
     assert(http->request != NULL);
     /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
-    http_reply const *reply = mem->getReply();
+    HttpReply const *reply = mem->getReply();
 
     if (headers_sz == 0)
         /* haven't found end of headers yet */
index 556f6f798baada95af899a778f3f644ac998ccca..1dbed06320c58ec8d3159eb2de89b90b2994d15c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: delay_pools.cc,v 1.36 2003/03/04 06:22:12 robertc Exp $
+ * $Id: delay_pools.cc,v 1.37 2003/03/06 11:51:55 robertc Exp $
  *
  * DEBUG: section 77    Delay Pools
  * AUTHOR: Robert Collins <robertc@squid-cache.org>
@@ -262,6 +262,10 @@ protected:
     DelaySpec spec;
     VectorMap<unsigned char, ClassCBucket> buckets;
 
+    class Id;
+
+    friend class ClassCHostPool::Id;
+
 class Id:public DelayIdComposite
     {
 
index 215e6bf2471df2d5f0405c973097227842c621e7..e3b642d32943bfe9b70621a6e42d6d834b6e66b4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: enums.h,v 1.228 2003/02/25 12:22:34 robertc Exp $
+ * $Id: enums.h,v 1.229 2003/03/06 11:51:55 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -549,8 +549,6 @@ typedef enum {
     MEM_HELPER_STATEFUL_REQUEST,
     MEM_HTTP_HDR_CC,
     MEM_HTTP_HDR_CONTENT_RANGE,
-    MEM_HTTP_HDR_ENTRY,
-    MEM_HTTP_REPLY,
     MEM_IPCACHE_ENTRY,
     MEM_MD5_DIGEST,
     MEM_NETDBENTRY,
index 8137ebe06582be17b5c19b5f81f5d376d8ee5932..dec5be920773458ab7d75199735186d3fe5937d2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.347 2003/03/06 06:21:37 robertc Exp $
+ * $Id: ftp.cc,v 1.348 2003/03/06 11:51:56 robertc Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -129,8 +129,14 @@ unsigned int datachannel_hack:
     1;
 };
 
-typedef struct _Ftpdata
+class FtpStateData
 {
+
+public:
+    void *operator new (size_t);
+    void operator delete (void *);
+    void deleteSelf() const;
+    ~FtpStateData();
     StoreEntry *entry;
     request_t *request;
     char user[MAX_URL];
@@ -186,9 +192,33 @@ typedef struct _Ftpdata
 
     struct _ftp_flags flags;
     FwdState *fwd;
+
+private:
+    CBDATA_CLASS(FtpStateData);
+};
+
+CBDATA_CLASS_INIT(FtpStateData);
+
+void *
+FtpStateData::operator new (size_t)
+{
+    CBDATA_INIT_TYPE(FtpStateData);
+    FtpStateData *result = cbdataAlloc(FtpStateData);
+    return result;
 }
 
-FtpStateData;
+void
+FtpStateData::operator delete (void *address)
+{
+    FtpStateData *t = static_cast<FtpStateData *>(address);
+    cbdataFree(t);
+}
+
+void
+FtpStateData::deleteSelf () const
+{
+    delete this;
+}
 
 typedef struct
 {
@@ -328,13 +358,12 @@ static void
 ftpStateFree(int fdnotused, void *data)
 {
     FtpStateData *ftpState = (FtpStateData *)data;
-    cbdataFree(ftpState);
+    ftpState->deleteSelf();
 }
 
-static void
-ftpStateFreed(void *data)
+FtpStateData::~FtpStateData()
 {
-    FtpStateData *ftpState = (FtpStateData *)data;
+    FtpStateData *ftpState = this;
 
     if (ftpState == NULL)
         return;
@@ -1317,7 +1346,6 @@ ftpBuildTitleUrl(FtpStateData * ftpState)
     ftpState->base_href.append("/");
 }
 
-CBDATA_TYPE(FtpStateData);
 void
 ftpStart(FwdState * fwd)
 {
@@ -1329,8 +1357,7 @@ ftpStart(FwdState * fwd)
     FtpStateData *ftpState;
     HttpReply *reply;
 
-    CBDATA_INIT_TYPE_FREECB(FtpStateData, ftpStateFreed);
-    ftpState = cbdataAlloc(FtpStateData);
+    ftpState = new FtpStateData;
     debug(9, 3) ("ftpStart: '%s'\n", url);
     statCounter.server.all.requests++;
     statCounter.server.ftp.requests++;
@@ -3021,7 +3048,7 @@ ftpAppendSuccessHeader(FtpStateData * ftpState)
     const char *filename = NULL;
     const char *t = NULL;
     StoreEntry *e = ftpState->entry;
-    http_reply *reply = httpReplyCreate ();
+    HttpReply *reply = httpReplyCreate ();
     http_version_t version;
 
     if (ftpState->flags.http_header_sent)
index 9f95e4b0cab1c1d353a3e17b50d802d27586c3b7..a3a8eb45dafd534e2f97feb5d0830b78034dec6d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mem.cc,v 1.75 2003/02/25 12:24:35 robertc Exp $
+ * $Id: mem.cc,v 1.76 2003/03/06 11:51:56 robertc Exp $
  *
  * DEBUG: section 13    High Level Memory Pool Management
  * AUTHOR: Harvest Derived
@@ -205,6 +205,18 @@ memAllocString(size_t net_size, size_t * gross_size)
     return pool ? memPoolAlloc(pool) : xcalloc(1, net_size);
 }
 
+extern size_t memStringCount();
+size_t
+memStringCount()
+{
+    size_t result = 0;
+
+    for (int counter = 0; counter < mem_str_pool_count; ++counter)
+        result += memPoolInUseCount(StrPools[counter].pool);
+
+    return result;
+}
+
 /* free buffer allocated with memAllocString() */
 void
 memFreeString(size_t size, void *buf)
@@ -388,8 +400,6 @@ Mem::Init(void)
     memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0);
     memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0);
     memDataInit(MEM_FWD_SERVER, "FwdServer", sizeof(FwdServer), 0);
-    memDataInit(MEM_HTTP_REPLY, "HttpReply", sizeof(HttpReply), 0);
-    memDataInit(MEM_HTTP_HDR_ENTRY, "HttpHeaderEntry", sizeof(HttpHeaderEntry), 0);
     memDataInit(MEM_HTTP_HDR_CC, "HttpHdrCc", sizeof(HttpHdrCc), 0);
     memDataInit(MEM_HTTP_HDR_CONTENT_RANGE, "HttpHdrContRange", sizeof(HttpHdrContRange), 0);
     memDataInit(MEM_NETDBENTRY, "netdbEntry", sizeof(netdbEntry), 0);
index 6afbdc799e74006d2f5d61f29bd8f7084296eafc..d197831f5026cada32d56c7c5a6b1ccf11d03ecd 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: net_db.cc,v 1.169 2003/02/21 22:50:10 robertc Exp $
+ * $Id: net_db.cc,v 1.170 2003/03/06 11:51:56 robertc Exp $
  *
  * DEBUG: section 38    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -1186,7 +1186,7 @@ netdbDeleteAddrNetwork(struct in_addr addr)
 void
 netdbBinaryExchange(StoreEntry * s)
 {
-    http_reply *reply = httpReplyCreate();
+    HttpReply *reply = httpReplyCreate();
     http_version_t version;
 #if USE_ICMP
 
index 5c3be4da0cbabb71d0cee9827818cb02945089b6..e682526f681468878f38bdbea5976310ef67372c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: peer_digest.cc,v 1.95 2003/02/21 22:50:10 robertc Exp $
+ * $Id: peer_digest.cc,v 1.96 2003/03/06 11:51:56 robertc Exp $
  *
  * DEBUG: section 72    Peer Digest Routines
  * AUTHOR: Alex Rousskov
@@ -105,7 +105,28 @@ peerDigestClean(PeerDigest * pd)
     pd->host.clean();
 }
 
-CBDATA_TYPE(PeerDigest);
+CBDATA_CLASS_INIT(PeerDigest);
+
+void *
+PeerDigest::operator new (size_t)
+{
+    CBDATA_INIT_TYPE(PeerDigest);
+    PeerDigest *result = cbdataAlloc(PeerDigest);
+    return result;
+}
+
+void
+PeerDigest::operator delete (void *address)
+{
+    PeerDigest *t = static_cast<PeerDigest *>(address);
+    cbdataFree(t);
+}
+
+void
+PeerDigest::deleteSelf () const
+{
+    delete this;
+}
 
 /* allocate new peer digest, call Init, and lock everything */
 PeerDigest *
@@ -114,8 +135,7 @@ peerDigestCreate(peer * p)
     PeerDigest *pd;
     assert(p);
 
-    CBDATA_INIT_TYPE(PeerDigest);
-    pd = cbdataAlloc(PeerDigest);
+    pd = new PeerDigest;
     peerDigestInit(pd, p);
 
     /* XXX This does not look right, and the same thing again in the caller */
@@ -136,7 +156,7 @@ peerDigestDestroy(PeerDigest * pd)
 
     peerDigestClean(pd);
 
-    cbdataFree(pd);
+    pd->deleteSelf();
 }
 
 /* called by peer to indicate that somebody actually needs this digest */
index ea9e30cef3d0b7b56f41eb53d3ff4d6529733f80..b3587eb5c1462642b034d2fecb1aeac7aeb7b21d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.470 2003/03/04 01:40:29 robertc Exp $
+ * $Id: protos.h,v 1.471 2003/03/06 11:51:57 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -286,7 +286,7 @@ SQUIDCEXTERN void whoisStart(FwdState *);
 /* http.c */
 SQUIDCEXTERN int httpCachable(method_t);
 SQUIDCEXTERN void httpStart(FwdState *);
-SQUIDCEXTERN void httpParseReplyHeaders(const char *, http_reply *);
+SQUIDCEXTERN void httpParseReplyHeaders(const char *, HttpReply *);
 SQUIDCEXTERN mb_size_t httpBuildRequestPrefix(request_t * request,
         request_t * orig_request,
         StoreEntry * entry,
index bdf1d72cbe2714922d6d5592c98975e789c9afa4..acd33f2ad43f39103375c436a7ca2d5714684237 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.456 2003/03/04 01:40:31 robertc Exp $
+ * $Id: structs.h,v 1.457 2003/03/06 11:51:57 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -824,7 +824,7 @@ struct _HttpBody
 #include "SquidString.h"
 /* http header extention field */
 
-struct _HttpHdrExtField
+class HttpHdrExtField
 {
     String name;               /* field-name  from HTTP/1.1 (no column after name) */
     String value;              /* field-value from HTTP/1.1 */
@@ -851,8 +851,12 @@ struct _TimeOrTag
 
 /* per field statistics */
 
-struct _HttpHeaderFieldStat
+class HttpHeaderFieldStat
 {
+
+public:
+    HttpHeaderFieldStat() : aliveCount(0), seenCount(0), parsCount(0), errCount(0), repCount(0){}
+
     int aliveCount;            /* created but not destroyed (count) */
     int seenCount;             /* #fields we've seen */
     int parsCount;             /* #parsing attempts */
@@ -862,19 +866,30 @@ struct _HttpHeaderFieldStat
 
 /* compiled version of HttpHeaderFieldAttrs plus stats */
 
-struct _HttpHeaderFieldInfo
+class HttpHeaderFieldInfo
 {
+
+public:
+    HttpHeaderFieldInfo() : id (HDR_ACCEPT), type (ftInvalid){}
+
     http_hdr_type id;
     String name;
     field_type type;
     HttpHeaderFieldStat stat;
 };
 
-struct _HttpHeaderEntry
+class HttpHeaderEntry
 {
+
+public:
+    void *operator new (size_t);
+    void operator delete (void *);
     http_hdr_type id;
     String name;
     String value;
+
+private:
+    static MemPool *Pool;
 };
 
 struct _HttpHeader
@@ -888,8 +903,12 @@ struct _HttpHeader
 
 class HttpHdrContRange;
 
-struct _HttpReply
+class HttpReply
 {
+
+public:
+    void *operator new (size_t);
+    void operator delete (void *);
     /* unsupported, writable, may disappear/change in the future */
     int hdr_sz;                        /* sums _stored_ status-line, headers, and <CRLF> */
 
@@ -911,6 +930,9 @@ struct _HttpReply
     HttpHeader header;
     HttpBody body;             /* for small constant memory-resident text bodies only */
     size_t maxBodySize;
+
+private:
+    static MemPool *Pool;
 };
 
 struct _http_state_flags
@@ -1106,9 +1128,14 @@ struct _cd_guess_stats
     int close_hits;            /* tmp, remove it later */
 };
 
-struct _PeerDigest
+class PeerDigest
 {
 
+public:
+    void *operator new (size_t);
+    void operator delete(void *);
+    void deleteSelf() const;
+
     struct _peer *peer;                        /* pointer back to peer structure, argh */
     CacheDigest *cd;           /* actual digest structure */
     String host;               /* copy of peer->host */
@@ -1159,6 +1186,9 @@ unsigned int requested:
     }
 
     stats;
+
+private:
+    CBDATA_CLASS(PeerDigest);
 };
 
 #endif
index 6e617ef732672fc70b24800030593704c9b11fe3..dd2745b52eb4a4eadc392b0c1aabb56fd81dbec4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: typedefs.h,v 1.157 2003/03/04 01:40:31 robertc Exp $
+ * $Id: typedefs.h,v 1.158 2003/03/06 11:51:58 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -111,13 +111,11 @@ class fde;
 
 typedef struct _fileMap fileMap;
 
-typedef struct _HttpReply http_reply;
-
 typedef struct _HttpStatusLine HttpStatusLine;
 
 typedef struct _HttpHeaderFieldAttrs HttpHeaderFieldAttrs;
 
-typedef struct _HttpHeaderFieldInfo HttpHeaderFieldInfo;
+class HttpHeaderFieldInfo;
 
 typedef struct _HttpHeader HttpHeader;
 
@@ -129,15 +127,15 @@ typedef struct _HttpHdrScTarget HttpHdrScTarget;
 
 typedef struct _TimeOrTag TimeOrTag;
 
-typedef struct _HttpHeaderEntry HttpHeaderEntry;
+class HttpHeaderEntry;
 
-typedef struct _HttpHeaderFieldStat HttpHeaderFieldStat;
+class HttpHeaderFieldStat;
 
 typedef struct _HttpHeaderStat HttpHeaderStat;
 
 typedef struct _HttpBody HttpBody;
 
-typedef struct _HttpReply HttpReply;
+class HttpReply;
 
 typedef struct _ConnCloseHelperData ConnCloseHelperData;
 
@@ -155,7 +153,7 @@ typedef struct _StoreDigestCBlock StoreDigestCBlock;
 
 typedef struct _DigestFetchState DigestFetchState;
 
-typedef struct _PeerDigest PeerDigest;
+class PeerDigest;
 
 typedef struct _peer peer;