From: Amos Jeffries Date: Wed, 1 Mar 2017 04:52:46 +0000 (+1300) Subject: Cleanup: convert MemObject::_reply to ReplyPointer X-Git-Tag: M-staged-PR71~236 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0c227a9f0631aa0718b997f2459f14803508238;p=thirdparty%2Fsquid.git Cleanup: convert MemObject::_reply to ReplyPointer --- diff --git a/src/MemObject.cc b/src/MemObject.cc index 3b95d034eb..69961aa19d 100644 --- a/src/MemObject.cc +++ b/src/MemObject.cc @@ -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 { 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 diff --git a/src/MemObject.h b/src/MemObject.h index 61206aeb88..23d716ef22 100644 --- a/src/MemObject.h +++ b/src/MemObject.h @@ -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) diff --git a/src/client_side.cc b/src/client_side.cc index 52314e2396..976b96b75a 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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); diff --git a/src/client_side.h b/src/client_side.h index 3876a87981..dfb9b0d6d3 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -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 *); diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index ca7e99d91d..4d824fd047 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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, diff --git a/src/http.cc b/src/http.cc index 625281c562..7c1281c04f 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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 diff --git a/src/refresh.cc b/src/refresh.cc index 67130b4e4b..9a72ad600b 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -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 && diff --git a/src/stmem.cc b/src/stmem.cc index 157f0dde51..f559cc3e5f 100644 --- a/src/stmem.cc +++ b/src/stmem.cc @@ -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" diff --git a/src/store.cc b/src/store.cc index fd91e44759..d974882f3b 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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(); diff --git a/src/tests/stub_MemObject.cc b/src/tests/stub_MemObject.cc index 88e8246e4c..da7a3b7325 100644 --- a/src/tests/stub_MemObject.cc +++ b/src/tests/stub_MemObject.cc @@ -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) diff --git a/src/tests/stub_client_side.cc b/src/tests/stub_client_side.cc index c83cddb465..1dfa58a746 100644 --- a/src/tests/stub_client_side.cc +++ b/src/tests/stub_client_side.cc @@ -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 diff --git a/src/tests/testSBuf.cc b/src/tests/testSBuf.cc index d4c03fb8bb..761d0636a9 100644 --- a/src/tests/testSBuf.cc +++ b/src/tests/testSBuf.cc @@ -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"