]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Review changes for I/O buffer conversion
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 23 Jan 2015 07:43:10 +0000 (23:43 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 23 Jan 2015 07:43:10 +0000 (23:43 -0800)
src/clients/Client.cc
src/clients/Client.h
src/http.cc

index 8ae2bc5b90e1d3dc2c8157045fb9c0f34e5e7ee8..b663ff2554559d39ad7778a1840a438d1e25f1d6 100644 (file)
@@ -974,12 +974,11 @@ Client::storeReplyBody(const char *data, ssize_t len)
 }
 
 size_t
-Client::needBufferSpace(const SBuf &readBuf, const size_t minSpace) const
+Client::calcBufferSpaceToReserve(size_t space, const size_t wantSpace) const
 {
-    size_t space = readBuf.spaceSize(); // available space w/o heroic measures
-    if (space < minSpace) {
+    if (space < wantSpace) {
         const size_t maxSpace = SBuf::maxSize; // absolute best
-        space = min(minSpace, maxSpace); // do not promise more than asked
+        space = min(wantSpace, maxSpace); // do not promise more than asked
     }
 
 #if USE_ADAPTATION
@@ -995,19 +994,14 @@ Client::needBufferSpace(const SBuf &readBuf, const size_t minSpace) const
          * the response ends sooner that BodyPipe frees up space:
          * There is no code to keep pumping data into the pipe once
          * response ends and serverComplete() is called.
-         *
-         * If the pipe is totally full, don't register the read handler.
-         * The BodyPipe will call our noteMoreBodySpaceAvailable() method
-         * when it has free space again.
          */
-        size_t adaptation_space =
-            virginBodyDestination->buf().potentialSpaceSize();
+        const size_t adaptor_space = virginBodyDestination->buf().potentialSpaceSize();
 
         debugs(11,9, "Client may read up to min(" <<
-               adaptation_space << ", " << space << ") bytes");
+               adaptor_space << ", " << space << ") bytes");
 
-        if (adaptation_space < space)
-            space = adaptation_space;
+        if (adaptor_space < space)
+            space = adaptor_space;
     }
 #endif
 
index 2c1ea94936daa75f0ae54c93c6b98e0de56e600c..ba9650d1d8000db97f11a8472554ed1f64482985 100644 (file)
@@ -143,10 +143,10 @@ protected:
     void adaptOrFinalizeReply();
     void addVirginReplyBody(const char *buf, ssize_t len);
     void storeReplyBody(const char *buf, ssize_t len);
-    /// \deprecated use SBuf I/O API and needBufferSpace() instead
+    /// \deprecated use SBuf I/O API and calcBufferSpaceToReserve() instead
     size_t replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const;
     /// determine how much space the buffer needs to reserve
-    size_t needBufferSpace(const SBuf &readBuf, const size_t minSpace) const;
+    size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const;
 
     void adjustBodyBytesRead(const int64_t delta);
 
index 15debce102b87d5c6c9d4f4eaddecc09b482486f..7938e18912dcb091bfa502f8b21b9832a489d8a8 100644 (file)
@@ -1140,7 +1140,7 @@ readDelayed(void *context, CommRead const &)
 void
 HttpStateData::readReply(const CommIoCbParams &io)
 {
-    assert(!flags.do_next_read); // XXX: should have been set false by mayReadVirginBody()
+    Must(!flags.do_next_read); // XXX: should have been set false by mayReadVirginBody()
     flags.do_next_read = false;
 
     debugs(11, 5, io.conn);
@@ -1156,8 +1156,8 @@ HttpStateData::readReply(const CommIoCbParams &io)
         return;
     }
 
-    assert(Comm::IsConnOpen(serverConnection));
-    assert(io.conn->fd == serverConnection->fd);
+    Must(Comm::IsConnOpen(serverConnection));
+    Must(io.conn->fd == serverConnection->fd);
 
     /*
      * Don't reset the timeout value here. The value should be
@@ -1546,9 +1546,9 @@ HttpStateData::maybeReadVirginBody()
     }
 
     // how much we want to read
-    const int read_size = needBufferSpace(inBuf, (limitBuffer - inBuf.length()));
+    const size_t read_size = calcBufferSpaceToReserve(inBuf.spaceSize(), (limitBuffer - inBuf.length()));
 
-    if (read_size < 1) {
+    if (!read_size) {
         debugs(11, 7, "wont read up to " << read_size << " into buffer (" << inBuf.length() << "/" << inBuf.spaceSize() << ") from " << serverConnection);
         return;
     }