From: robertc <> Date: Thu, 6 Mar 2003 18:51:55 +0000 (+0000) Subject: Summary: Merge String loss fix. X-Git-Tag: SQUID_3_0_PRE1~279 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0353e7241e73894b614e9c07277adae642f9da2e;p=thirdparty%2Fsquid.git Summary: Merge String loss fix. 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. --- diff --git a/include/splay.h b/include/splay.h index d9d15ba750..f606e8121e 100644 --- a/include/splay.h +++ b/include/splay.h @@ -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 * 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::insert(Value data, SPLAYCMP * compare) SplayNode *newNode = new SplayNode; newNode->data = data; if (this == NULL) { + splayLastResult = -1; newNode->left = newNode->right = NULL; return newNode; } @@ -214,6 +218,24 @@ Splay::find (Value const &value, SPLAYCMP *compare) const return &head->data; } +template +void +Splay::insert(Value const &value, SPLAYCMP *compare) +{ + assert (!find (value, compare)); + head = head->insert(value, compare); + ++elements; +} + +template +void +Splay::remove(Value const &value, SPLAYCMP *compare) +{ + assert (find (value, compare)); + head = head->remove(value, compare); + --elements; +} + #endif #endif /* SQUID_SPLAY_H */ diff --git a/src/DelayUser.h b/src/DelayUser.h index 0ebfb6e3db..9973467e1b 100644 --- a/src/DelayUser.h +++ b/src/DelayUser.h @@ -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 @@ -101,6 +101,8 @@ class Id:public DelayIdComposite DelayUserBucket::Pointer theBucket; }; + friend class Id; + DelaySpec spec; Splay buckets; }; diff --git a/src/DelayVector.h b/src/DelayVector.h index 22c0f4b058..5dc21a84c2 100644 --- a/src/DelayVector.h +++ b/src/DelayVector.h @@ -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::const_iterator const_iterator; }; + friend class Id; + Vector pools; typedef Vector::iterator iterator; typedef Vector::const_iterator const_iterator; diff --git a/src/HttpHdrExtField.cc b/src/HttpHdrExtField.cc index ba25aa3639..b4fbd38382 100644 --- a/src/HttpHdrExtField.cc +++ b/src/HttpHdrExtField.cc @@ -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 * diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index e0ea9586a1..20b678f24b 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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); +} diff --git a/src/HttpHeaderRange.h b/src/HttpHeaderRange.h index e9e05e8195..db72900604 100644 --- a/src/HttpHeaderRange.h +++ b/src/HttpHeaderRange.h @@ -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 diff --git a/src/HttpHeaderTools.cc b/src/HttpHeaderTools.cc index 5a2897a865..9b5aea92ae 100644 --- a/src/HttpHeaderTools.cc +++ b/src/HttpHeaderTools.cc @@ -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 diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 497d9435d5..2e1629c5c9 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -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); +} diff --git a/src/SquidString.h b/src/SquidString.h index a0bf3eab22..167fa68dba 100644 --- a/src/SquidString.h +++ b/src/SquidString.h @@ -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 @@ -36,6 +36,43 @@ #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::SPLAYWALKEE Stater; + + Splay 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 */ diff --git a/src/String.cc b/src/String.cc index a962c703e2..93140f8515 100644 --- a/src/String.cc +++ b/src/String.cc @@ -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 @@ -34,11 +34,12 @@ */ #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 +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 diff --git a/src/String.cci b/src/String.cci index 8784518582..045821c5e6 100644 --- a/src/String.cci +++ b/src/String.cci @@ -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 @@ -34,7 +34,11 @@ */ String::String() : size_(0), len_(0), buf_ (NULL) -{} +{ +#if DEBUGSTRINGS + StringRegistry::Instance().add(this); +#endif +} int String::size() const diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index cefa29be70..699b94cc59 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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 */ diff --git a/src/delay_pools.cc b/src/delay_pools.cc index 556f6f798b..1dbed06320 100644 --- a/src/delay_pools.cc +++ b/src/delay_pools.cc @@ -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 @@ -262,6 +262,10 @@ protected: DelaySpec spec; VectorMap buckets; + class Id; + + friend class ClassCHostPool::Id; + class Id:public DelayIdComposite { diff --git a/src/enums.h b/src/enums.h index 215e6bf247..e3b642d329 100644 --- a/src/enums.h +++ b/src/enums.h @@ -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, diff --git a/src/ftp.cc b/src/ftp.cc index 8137ebe065..dec5be9207 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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(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) diff --git a/src/mem.cc b/src/mem.cc index 9f95e4b0ca..a3a8eb45da 100644 --- a/src/mem.cc +++ b/src/mem.cc @@ -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); diff --git a/src/net_db.cc b/src/net_db.cc index 6afbdc799e..d197831f50 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -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 diff --git a/src/peer_digest.cc b/src/peer_digest.cc index 5c3be4da0c..e682526f68 100644 --- a/src/peer_digest.cc +++ b/src/peer_digest.cc @@ -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(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 */ diff --git a/src/protos.h b/src/protos.h index ea9e30cef3..b3587eb5c1 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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, diff --git a/src/structs.h b/src/structs.h index bdf1d72cbe..acd33f2ad4 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 */ @@ -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 diff --git a/src/typedefs.h b/src/typedefs.h index 6e617ef732..dd2745b52e 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -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;