]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Extend Client API to estimate needed buffer space using an SBuf
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 11 Nov 2014 13:41:59 +0000 (05:41 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 11 Nov 2014 13:41:59 +0000 (05:41 -0800)
Add Client::needBufferSpace() API method to estimate reuired buffer
space based on an SBuf buffer.

Deprecate the badly named Client::replyBodySpace() method and MemBuf API
for server connection I/O.

src/clients/Client.cc
src/clients/Client.h

index d09833ca28cd0826e788c98f84e6269b36e71186..ae6502a5d30689c297c9cf2762d990048d7bc4cf 100644 (file)
@@ -973,8 +973,49 @@ Client::storeReplyBody(const char *data, ssize_t len)
     currentOffset += len;
 }
 
-size_t Client::replyBodySpace(const MemBuf &readBuf,
-                                       const size_t minSpace) const
+size_t
+Client::needBufferSpace(const SBuf &readBuf, const size_t minSpace) const
+{
+    size_t space = readBuf.spaceSize(); // available space w/o heroic measures
+    if (space < minSpace) {
+        const size_t maxSpace = SBuf::maxSize; // absolute best
+        space = min(minSpace, maxSpace); // do not promise more than asked
+    }
+
+#if USE_ADAPTATION
+    if (responseBodyBuffer) {
+        return 0;      // Stop reading if already overflowed waiting for ICAP to catch up
+    }
+
+    if (virginBodyDestination != NULL) {
+        /*
+         * BodyPipe buffer has a finite size limit.  We
+         * should not read more data from the network than will fit
+         * into the pipe buffer or we _lose_ what did not fit if
+         * 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();
+
+        debugs(11,9, "Client may read up to min(" <<
+               adaptation_space << ", " << space << ") bytes");
+
+        if (adaptation_space < space)
+            space = adaptation_space;
+    }
+#endif
+
+    return space;
+}
+
+size_t
+Client::replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const
 {
     size_t space = readBuf.spaceSize(); // available space w/o heroic measures
     if (space < minSpace) {
index 40c508e9b7a267b96e9ef3d55446702c17a4c0ff..a9a75bb97578d54d9793b77bd814fb150cedf13f 100644 (file)
@@ -143,7 +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
     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;
 
     void adjustBodyBytesRead(const int64_t delta);