]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Simplified MemObject::write() API.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 8 Jun 2013 00:56:36 +0000 (18:56 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sat, 8 Jun 2013 00:56:36 +0000 (18:56 -0600)
The API required a callback, but the call was always synchronous and the
required callback mechanism could not reliably support an async call anyway.

The method adjusted the buffer offset to become relative to headers rather
than body. While the intent to separate headers from body is noble, none of
the existing caches support that separation, and a different API will be
needed to support it correctly anyway. For now, let's reduce the number of
special cases and offset manipulations.

src/MemObject.cc
src/MemObject.h
src/store.cc
src/store_client.cc

index 81884c0b93ade7536dae7ae1040dc19e389cdcb1..7620d1195eecfe72cf9bd4e6a4b378ecc29a004d 100644 (file)
@@ -150,21 +150,17 @@ MemObject::unlinkRequest()
 }
 
 void
-MemObject::write ( StoreIOBuffer writeBuffer, STMCB *callback, void *callbackData)
+MemObject::write(const StoreIOBuffer &writeBuffer)
 {
     PROF_start(MemObject_write);
     debugs(19, 6, "memWrite: offset " << writeBuffer.offset << " len " << writeBuffer.length);
 
-    /* the offset is into the content, not the headers */
-    writeBuffer.offset += (_reply ? _reply->hdr_sz : 0);
-
     /* We don't separate out mime headers yet, so ensure that the first
      * write is at offset 0 - where they start
      */
     assert (data_hdr.endOffset() || writeBuffer.offset == 0);
 
     assert (data_hdr.write (writeBuffer));
-    callback (callbackData, writeBuffer);
     PROF_stop(MemObject_write);
 }
 
index cee4c9e3e270edead6fb4f90a02a05c3f47f9b4c..5c9af1868b2864420e8dbeffc3e8e796901e25f7 100644 (file)
@@ -63,7 +63,7 @@ public:
     /// replaces construction-time URLs with correct ones; see hidden_mem_obj
     void resetUrls(char const *aUrl, char const *aLog_url);
 
-    void write(StoreIOBuffer, STMCB *, void *);
+    void write(const StoreIOBuffer &buf);
     void unlinkRequest();
     HttpReply const *getReply() const;
     void replaceHttpReply(HttpReply *newrep);
index 24f707fee8680020db5b44d80282f64f050462a1..fccf0e01a8399e6098c1516eb6107b135c867538 100644 (file)
@@ -74,8 +74,6 @@
 #include <limits.h>
 #endif
 
-static STMCB storeWriteComplete;
-
 #define REBUILD_TIMESTAMP_DELTA_MAX 2
 
 #define STORE_IN_MEM_BUCKETS            (229)
@@ -869,21 +867,6 @@ StoreEntry::expireNow()
     expires = squid_curtime;
 }
 
-void
-storeWriteComplete (void *data, StoreIOBuffer wroteBuffer)
-{
-    PROF_start(storeWriteComplete);
-    StoreEntry *e = (StoreEntry *)data;
-
-    if (EBIT_TEST(e->flags, DELAY_SENDING)) {
-        PROF_stop(storeWriteComplete);
-        return;
-    }
-
-    e->invokeHandlers();
-    PROF_stop(storeWriteComplete);
-}
-
 void
 StoreEntry::write (StoreIOBuffer writeBuffer)
 {
@@ -892,10 +875,17 @@ StoreEntry::write (StoreIOBuffer writeBuffer)
     PROF_start(StoreEntry_write);
     assert(store_status == STORE_PENDING);
 
+    // XXX: caller uses content offset, but we also store headers
+    if (const HttpReply *reply = mem_obj->getReply())
+        writeBuffer.offset += reply->hdr_sz;
+
     debugs(20, 5, "storeWrite: writing " << writeBuffer.length << " bytes for '" << getMD5Text() << "'");
     PROF_stop(StoreEntry_write);
     storeGetMemSpace(writeBuffer.length);
-    mem_obj->write (writeBuffer, storeWriteComplete, this);
+    mem_obj->write(writeBuffer);
+
+    if (!EBIT_TEST(flags, DELAY_SENDING))
+        invokeHandlers();
 }
 
 /* Append incoming data from a primary server to an entry. */
index 3c6c4186f1500ff0539e1a810af699e635a40da7..540b8286cbe90c0ccf7049c59641eb0f866c17b3 100644 (file)
@@ -479,12 +479,6 @@ store_client::fileRead()
               this);
 }
 
-static void
-storeClientMemWriteComplete(void *data, StoreIOBuffer wroteBuffer)
-{
-    // Nothin to do here but callback is needed
-}
-
 void
 store_client::readBody(const char *buf, ssize_t len)
 {
@@ -512,15 +506,11 @@ store_client::readBody(const char *buf, ssize_t len)
         // The above may start to free our object so we need to check again
         if (entry->mem_obj->inmem_lo == 0) {
             /* Copy read data back into memory.
-             * but first we need to adjust offset.. some parts of the code
-             * counts offset including headers, some parts count offset as
-             * withing the body.. copyInto is including headers, but the mem
-             * cache expects offset without headers (using negative for headers)
-             * eventually not storing packed headers in memory at all.
+             * copyInto.offset includes headers, which is what mem cache needs
              */
             int64_t mem_offset = entry->mem_obj->endOffset();
             if ((copyInto.offset == mem_offset) || (parsed_header && mem_offset == rep->hdr_sz)) {
-                entry->mem_obj->write(StoreIOBuffer(len, copyInto.offset - rep->hdr_sz, copyInto.data), storeClientMemWriteComplete, this);
+                entry->mem_obj->write(StoreIOBuffer(len, copyInto.offset, copyInto.data));
             }
         }
     }