]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/MemObject.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / MemObject.cc
index 815bf9bbee4d04c94180f44b33b9e3c9bfd0452a..b35d26cae619f7c153c521851950940a2ebce921 100644 (file)
  *
  */
 
-#include "squid.h"
+#include "squid-old.h"
+#include "comm/Connection.h"
 #include "MemObject.h"
 #include "HttpRequest.h"
 #include "HttpReply.h"
 #include "Store.h"
 #include "StoreClient.h"
 #include "Generic.h"
-#if DELAY_POOLS
+#if USE_DELAY_POOLS
 #include "DelayPools.h"
 #endif
 #include "MemBuf.h"
@@ -57,7 +58,7 @@ url_checksum(const char *url)
     SquidMD5Init(&M);
     SquidMD5Update(&M, (unsigned char *) url, strlen(url));
     SquidMD5Final(digest, &M);
-    xmemcpy(&ck, digest, sizeof(ck));
+    memcpy(&ck, digest, sizeof(ck));
     return ck;
 }
 
@@ -71,6 +72,15 @@ MemObject::inUseCount()
     return Pool().inUseCount();
 }
 
+void
+MemObject::resetUrls(char const *aUrl, char const *aLog_url)
+{
+    safe_free(url);
+    safe_free(log_url);    /* XXX account log_url */
+    log_url = xstrdup(aLog_url);
+    url = xstrdup(aUrl);
+}
+
 MemObject::MemObject(char const *aUrl, char const *aLog_url)
 {
     debugs(20, 3, HERE << "new MemObject " << this);
@@ -90,6 +100,8 @@ MemObject::MemObject(char const *aUrl, char const *aLog_url)
     object_sz = -1;
 
     /* XXX account log_url */
+
+    swapout.decision = SwapOut::swNeedsCheck;
 }
 
 MemObject::~MemObject()
@@ -207,10 +219,12 @@ struct StoreClientStats : public unary_function<store_client, void> {
 };
 
 void
-MemObject::stat (MemBuf * mb) const
+MemObject::stat(MemBuf * mb) const
 {
     mb->Printf("\t%s %s\n",
                RequestMethodStr(method), log_url);
+    if (vary_headers)
+        mb->Printf("\tvary_headers: %s\n", vary_headers);
     mb->Printf("\tinmem_lo: %"PRId64"\n", inmem_lo);
     mb->Printf("\tinmem_hi: %"PRId64"\n", data_hdr.endOffset());
     mb->Printf("\tswapout: %"PRId64" bytes queued\n",
@@ -231,6 +245,15 @@ MemObject::endOffset () const
     return data_hdr.endOffset();
 }
 
+void
+MemObject::markEndOfReplyHeaders()
+{
+    const int hdr_sz = endOffset();
+    assert(hdr_sz >= 0);
+    assert(_reply);
+    _reply->hdr_sz = hdr_sz;
+}
+
 int64_t
 MemObject::size() const
 {
@@ -240,6 +263,23 @@ MemObject::size() const
     return object_sz;
 }
 
+int64_t
+MemObject::expectedReplySize() const
+{
+    debugs(20, 7, HERE << "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: HttpMsg sets hdr_sz to 0
+            return clen + _reply->hdr_sz;
+    }
+
+    return -1; // not enough information to predict
+}
+
 void
 MemObject::reset()
 {
@@ -339,7 +379,7 @@ MemObject::trimSwappable()
      * there will be a chunk of the data which is not in memory
      * and is not yet on disk.
      * The -1 makes sure the page isn't freed until storeSwapOut has
-     * walked to the next page. (mem->swapout.memnode)
+     * walked to the next page.
      */
     int64_t on_disk;
 
@@ -377,7 +417,7 @@ MemObject::isContiguous() const
 int
 MemObject::mostBytesWanted(int max) const
 {
-#if DELAY_POOLS
+#if USE_DELAY_POOLS
     /* identify delay id with largest allowance */
     DelayId largestAllowance = mostBytesAllowed ();
     return largestAllowance.bytesWanted(0, max);
@@ -390,7 +430,7 @@ MemObject::mostBytesWanted(int max) const
 void
 MemObject::setNoDelay(bool const newValue)
 {
-#if DELAY_POOLS
+#if USE_DELAY_POOLS
 
     for (dlink_node *node = clients.head; node; node = node->next) {
         store_client *sc = (store_client *) node->data;
@@ -412,7 +452,7 @@ MemObject::kickReads()
     deferredReads.kickReads(-1);
 }
 
-#if DELAY_POOLS
+#if USE_DELAY_POOLS
 DelayId
 MemObject::mostBytesAllowed() const
 {
@@ -452,3 +492,9 @@ MemObject::mostBytesAllowed() const
 }
 
 #endif
+
+int64_t
+MemObject::availableForSwapOut() const
+{
+    return endOffset() - swapout.queue_offset;
+}