]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: convert MemObject::_reply to ReplyPointer
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 1 Mar 2017 04:52:46 +0000 (17:52 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 1 Mar 2017 04:52:46 +0000 (17:52 +1300)
12 files changed:
src/MemObject.cc
src/MemObject.h
src/client_side.cc
src/client_side.h
src/client_side_reply.cc
src/http.cc
src/refresh.cc
src/stmem.cc
src/store.cc
src/tests/stub_MemObject.cc
src/tests/stub_client_side.cc
src/tests/testSBuf.cc

index 3b95d034ebd354af3873646027daffe807352d7d..69961aa19d21736d9312e0c8dfb477042bcb4d2f 100644 (file)
@@ -95,7 +95,6 @@ MemObject::MemObject() :
     inmem_lo(0),
     nclients(0),
     smpCollapsed(false),
-    request(nullptr),
     ping_reply_callback(nullptr),
     ircb_data(nullptr),
     id(0),
@@ -109,8 +108,7 @@ MemObject::MemObject() :
     debugs(20, 3, "new MemObject " << this);
     memset(&start_ping, 0, sizeof(start_ping));
     memset(&abort, 0, sizeof(abort));
-    _reply = new HttpReply;
-    HTTPMSGLOCK(_reply);
+    reply_ = new HttpReply;
 }
 
 MemObject::~MemObject()
@@ -139,8 +137,6 @@ MemObject::~MemObject()
 
 #endif
 
-    HTTPMSGUNLOCK(_reply);
-
     ctx_exit(ctx);              /* must exit before we free mem->url */
 }
 
@@ -172,26 +168,12 @@ MemObject::dump() const
     debugs(20, DBG_IMPORTANT, "MemObject->inmem_hi: " << data_hdr.endOffset());
     debugs(20, DBG_IMPORTANT, "MemObject->inmem_lo: " << inmem_lo);
     debugs(20, DBG_IMPORTANT, "MemObject->nclients: " << nclients);
-    debugs(20, DBG_IMPORTANT, "MemObject->reply: " << _reply);
+    debugs(20, DBG_IMPORTANT, "MemObject->reply: " << reply_);
     debugs(20, DBG_IMPORTANT, "MemObject->request: " << request);
     debugs(20, DBG_IMPORTANT, "MemObject->logUri: " << logUri_);
     debugs(20, DBG_IMPORTANT, "MemObject->storeId: " << storeId_);
 }
 
-HttpReply const *
-MemObject::getReply() const
-{
-    return _reply;
-}
-
-void
-MemObject::replaceHttpReply(HttpReply *newrep)
-{
-    HTTPMSGUNLOCK(_reply);
-    _reply = newrep;
-    HTTPMSGLOCK(_reply);
-}
-
 struct LowestMemReader : public unary_function<store_client, void> {
     LowestMemReader(int64_t seed):current(seed) {}
 
@@ -253,8 +235,8 @@ MemObject::markEndOfReplyHeaders()
 {
     const int hdr_sz = endOffset();
     assert(hdr_sz >= 0);
-    assert(_reply);
-    _reply->hdr_sz = hdr_sz;
+    assert(reply_);
+    reply_->hdr_sz = hdr_sz;
 }
 
 int64_t
@@ -269,15 +251,15 @@ MemObject::size() const
 int64_t
 MemObject::expectedReplySize() const
 {
-    debugs(20, 7, HERE << "object_sz: " << object_sz);
+    debugs(20, 7, "object_sz: " << object_sz);
     if (object_sz >= 0) // complete() has been called; we know the exact answer
         return object_sz;
 
-    if (_reply) {
-        const int64_t clen = _reply->bodySize(method);
-        debugs(20, 7, HERE << "clen: " << clen);
-        if (clen >= 0 && _reply->hdr_sz > 0) // yuck: Http::Message sets hdr_sz to 0
-            return clen + _reply->hdr_sz;
+    if (reply_) {
+        const int64_t clen = reply_->bodySize(method);
+        debugs(20, 7, "clen: " << clen);
+        if (clen >= 0 && reply_->hdr_sz > 0) // yuck: Http::Message sets hdr_sz to 0
+            return clen + reply_->hdr_sz;
     }
 
     return -1; // not enough information to predict
@@ -290,6 +272,8 @@ MemObject::reset()
     data_hdr.freeContent();
     inmem_lo = 0;
     /* Should we check for clients? */
+    if (reply_)
+        reply_->reset();
 }
 
 int64_t
index 61206aeb885fdf6e94b813cc73a5831952c63154..23d716ef2246fe301f3a08d6e2771d763a64eb90 100644 (file)
@@ -47,11 +47,11 @@ public:
 
     void write(const StoreIOBuffer &buf);
     void unlinkRequest() { request = nullptr; }
-    HttpReply const *getReply() const;
-    void replaceHttpReply(HttpReply *newrep);
+    const HttpReplyPointer &getReply() const { return reply_; }
+    void replaceReply(const HttpReplyPointer &r) { reply_ = r; }
     void stat (MemBuf * mb) const;
     int64_t endOffset () const;
-    void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
+    void markEndOfReplyHeaders(); ///< sets reply_->hdr_sz to endOffset()
     /// negative if unknown; otherwise, expected object_sz, expected endOffset
     /// maximum, and stored reply headers+body size (all three are the same)
     int64_t expectedReplySize() const;
@@ -174,7 +174,7 @@ public:
     void kickReads();
 
 private:
-    HttpReply *_reply;
+    HttpReplyPointer reply_;
 
     mutable String storeId_; ///< StoreId for our entry (usually request URI)
     mutable String logUri_;  ///< URI used for logging (usually request URI)
index 52314e23961f51989ee3e7917bd64dc99062159f..976b96b75a8f37ed2f5f7c1acd3ea9c95039bb9a 100644 (file)
@@ -700,7 +700,7 @@ clientPackTermBound(String boundary, MemBuf *mb)
 }
 
 void
-clientPackRangeHdr(const HttpReply * rep, const HttpHdrRangeSpec * spec, String boundary, MemBuf * mb)
+clientPackRangeHdr(const HttpReplyPointer &rep, const HttpHdrRangeSpec * spec, String boundary, MemBuf * mb)
 {
     HttpHeader hdr(hoReply);
     assert(rep);
index 3876a87981609c87e4140940807d4502aa6edca3..dfb9b0d6d34a6ab96b304fb24dadf21ad8d9645c 100644 (file)
@@ -403,7 +403,7 @@ void httpRequestFree(void *);
 void clientSetKeepaliveFlag(ClientHttpRequest *http);
 
 /// append a "part" HTTP header (as in a multi-part/range reply) to the buffer
-void clientPackRangeHdr(const HttpReply *, const HttpHdrRangeSpec *, String boundary, MemBuf *);
+void clientPackRangeHdr(const HttpReplyPointer &, const HttpHdrRangeSpec *, String boundary, MemBuf *);
 
 /// put terminating boundary for multiparts to the buffer
 void clientPackTermBound(String boundary, MemBuf *);
index ca7e99d91dfa2dd5725cad632ce05bdd03be8c59..4d824fd04724adc314a86ac61d26c3c91a9d4e19 100644 (file)
@@ -1185,13 +1185,14 @@ clientReplyContext::storeNotOKTransferDone() const
     MemObject *mem = http->storeEntry()->mem_obj;
     assert(mem != NULL);
     assert(http->request != NULL);
-    /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
-    HttpReply const *curReply = mem->getReply();
 
+    /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
     if (headers_sz == 0)
         /* haven't found end of headers yet */
         return 0;
 
+    const HttpReplyPointer curReply(mem->getReply());
+
     /*
      * Figure out how much data we are supposed to send.
      * If we are sending a body and we don't have a content-length,
index 625281c5624d1ace958364bf253c5511676c864b..7c1281c04fcf874406cdd75cce78d6707f6fc9c2 100644 (file)
@@ -872,7 +872,7 @@ HttpStateData::peerSupportsConnectionPinning() const
     if (!_peer->connection_auth)
         return false;
 
-    const HttpReply *rep = entry->mem_obj->getReply();
+    const HttpReplyPointer rep(entry->mem_obj->getReply());
 
     /*The peer supports connection pinning and the http reply status
       is not unauthorized, so the related connection can be pinned
index 67130b4e4b87e64e5279dbd1c45e1c0fe22fa61a..9a72ad600b34d5bfe299201db20e89c8dd4c5561 100644 (file)
@@ -327,7 +327,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
 
     debugs(22, 3, "Staleness = " << staleness);
 
-    const auto *reply = (entry->mem_obj && entry->mem_obj->getReply() ? entry->mem_obj->getReply() : nullptr);
+    const HttpReplyPointer reply(entry->mem_obj && entry->mem_obj->getReply() ? entry->mem_obj->getReply() : nullptr);
 
     // stale-if-error requires any failure be passed thru when its period is over.
     if (request && reply && reply->cache_control &&
index 157f0dde516ef1cbed3d345758e1f44e20fddf71..f559cc3e5fd202d0a230018cbfb66ad2448b631a 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "squid.h"
 #include "Generic.h"
-#include "HttpRequest.h"
+#include "HttpReply.h"
 #include "mem_node.h"
 #include "MemObject.h"
 #include "profiler/Profiler.h"
index fd91e447599d621895cbb45cb4b727c75adfc0db..d974882f3be3bb31197f7ba6403e49ce27b33e7e 100644 (file)
@@ -726,7 +726,7 @@ StoreEntry::adjustVary()
 
         /* Make sure the request knows the variance status */
         if (request->vary_headers.isEmpty())
-            request->vary_headers = httpMakeVaryMark(request.getRaw(), mem_obj->getReply());
+            request->vary_headers = httpMakeVaryMark(request.getRaw(), mem_obj->getReply().getRaw());
     }
 
     // TODO: storeGetPublic() calls below may create unlocked entries.
@@ -826,7 +826,7 @@ StoreEntry::write (StoreIOBuffer writeBuffer)
     assert(store_status == STORE_PENDING);
 
     // XXX: caller uses content offset, but we also store headers
-    if (const HttpReply *reply = mem_obj->getReply())
+    if (const HttpReplyPointer reply = mem_obj->getReply())
         writeBuffer.offset += reply->hdr_sz;
 
     debugs(20, 5, "storeWrite: writing " << writeBuffer.length << " bytes for '" << getMD5Text() << "'");
@@ -1731,22 +1731,17 @@ StoreEntry::contentLen() const
 }
 
 HttpReply const *
-StoreEntry::getReply () const
+StoreEntry::getReply() const
 {
-    if (NULL == mem_obj)
-        return NULL;
-
-    return mem_obj->getReply();
+    return (mem_obj ? mem_obj->getReply().getRaw() : nullptr);
 }
 
 void
 StoreEntry::reset()
 {
     assert (mem_obj);
-    debugs(20, 3, "StoreEntry::reset: " << url());
+    debugs(20, 3, url());
     mem_obj->reset();
-    HttpReply *rep = (HttpReply *) getReply();       // bypass const
-    rep->reset();
     expires = lastModified_ = timestamp = -1;
 }
 
@@ -1857,7 +1852,7 @@ StoreEntry::replaceHttpReply(HttpReply *rep, bool andStartWriting)
         return;
     }
 
-    mem_obj->replaceHttpReply(rep);
+    mem_obj->replaceReply(HttpReplyPointer(rep));
 
     if (andStartWriting)
         startWriting();
index 88e8246e4cbecc6cc7f73ad35f93ab169e5116ba..da7a3b7325b255275be876854f42dff851fea6da 100644 (file)
@@ -32,24 +32,17 @@ int64_t MemObject::policyLowestOffsetToKeep(bool swap) const STUB_RETVAL(-1)
 MemObject::MemObject() :
     inmem_lo(0),
     nclients(0),
-    request(NULL),
     ping_reply_callback(NULL),
     ircb_data(NULL),
     id(0),
     object_sz(-1),
-    swap_hdr_sz(0),
-    _reply(NULL)
+    swap_hdr_sz(0)
 {
     memset(&clients, 0, sizeof(clients));
     memset(&start_ping, 0, sizeof(start_ping));
     memset(&abort, 0, sizeof(abort));
 } // NOP instead of elided due to Store
 
-HttpReply const * MemObject::getReply() const
-{
-    // XXX: required by testStore
-    return NULL;
-}
 const char *MemObject::storeId() const STUB_RETVAL(NULL)
 const char *MemObject::logUri() const STUB_RETVAL(NULL)
 void MemObject::setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod) STUB
@@ -63,7 +56,6 @@ int MemObject::mostBytesWanted(int max, bool ignoreDelayPools) const STUB_RETVAL
 DelayId MemObject::mostBytesAllowed() const STUB_RETVAL(DelayId())
 #endif
 void MemObject::write(const StoreIOBuffer &writeBuffer) STUB
-void MemObject::replaceHttpReply(HttpReply *newrep) STUB
 int64_t MemObject::lowestMemReaderOffset() const STUB_RETVAL(0)
 void MemObject::kickReads() STUB
 int64_t MemObject::objectBytesOnDisk() const STUB_RETVAL(0)
index c83cddb46563abebef0f672393f536be62e9a6c1..1dfa58a7466eb53ea1f2c03ebb78d9a2636fca42 100644 (file)
@@ -57,6 +57,6 @@ int varyEvaluateMatch(StoreEntry *, HttpRequest *) STUB_RETVAL(0)
 void clientOpenListenSockets(void) STUB
 void clientHttpConnectionsClose(void) STUB
 void httpRequestFree(void *) STUB
-void clientPackRangeHdr(const HttpReply *, const HttpHdrRangeSpec *, String, MemBuf *) STUB
+void clientPackRangeHdr(const HttpReplyPointer &, const HttpHdrRangeSpec *, String, MemBuf *) STUB
 void clientPackTermBound(String, MemBuf *) STUB
 
index d4c03fb8bb7b559f571d6c1fcd523a1a4e87c445..761d0636a921601925bf38c6fb1ad4c23d5f8527 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "squid.h"
 #include "base/CharacterSet.h"
-#include "HttpRequest.h"
+#include "HttpReply.h"
 #include "sbuf/Algorithms.h"
 #include "sbuf/SBuf.h"
 #include "sbuf/Stream.h"