]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Merged from trunk
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 27 Jul 2015 13:40:19 +0000 (15:40 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 27 Jul 2015 13:40:19 +0000 (15:40 +0200)
src/SBuf.cc
src/adaptation/icap/ModXact.cc
src/adaptation/icap/Xaction.cc

index 1c40c9c95e7fff1d846c40545cc9ef8854baadc4..412f2fde393669024ac7a3c494a847cef0107fba 100644 (file)
@@ -565,12 +565,18 @@ SBuf::c_str()
 SBuf&
 SBuf::chop(size_type pos, size_type n)
 {
-    if (pos == npos || pos > length() || n == 0) {
+    if (pos == npos || pos > length())
+        pos = length();
+
+    if (n == npos || (pos+n) > length())
+        n = length() - pos;
+
+    // if there will be nothing left, reset the buffer while we can
+    if (pos == length() || n == 0) {
         clear();
         return *this;
     }
-    if (n == npos || (pos+n) > length())
-        n = length()-pos;
+
     ++stats.chop;
     off_ += pos;
     len_ = n;
index 8fb8f1109973ae65c303a0c5a463e82474dcf4de..8cb90777f6abcb07e7ba38de81fb80466313df67 100644 (file)
@@ -557,10 +557,10 @@ void Adaptation::Icap::ModXact::readMore()
         return;
     }
 
-    if (readBuf.spaceSize())
+    if (readBuf.length() < SQUID_TCP_SO_RCVBUF)
         scheduleRead();
     else
-        debugs(93,3,HERE << "nothing to do because !readBuf.spaceSize()");
+        debugs(93,3,HERE << "cannot read with a full buffer");
 }
 
 // comm module read a portion of the ICAP response for us
index e731ad2af69503a9473c2df4e70cb28abf6fb904..c2df9526342abb25daf262386800a24266a4d70c 100644 (file)
@@ -456,6 +456,11 @@ void Adaptation::Icap::Xaction::noteCommRead(const CommIoCbParams &io)
 
     // TODO: tune this better to expected message sizes
     readBuf.reserveCapacity(SQUID_TCP_SO_RCVBUF);
+    // we are not asked to grow beyond the allowed maximum
+    Must(readBuf.length() < SQUID_TCP_SO_RCVBUF);
+    // now we can ensure that there is space to read new data,
+    // even if readBuf.spaceSize() currently returns zero.
+    readBuf.rawSpace(1);
 
     CommIoCbParams rd(this); // will be expanded with ReadNow results
     rd.conn = io.conn;
@@ -534,7 +539,7 @@ bool Adaptation::Icap::Xaction::parseHttpMsg(HttpMsg *msg)
 bool Adaptation::Icap::Xaction::mayReadMore() const
 {
     return !doneReading() && // will read more data
-           readBuf.spaceSize();  // have space for more data
+           readBuf.length() < SQUID_TCP_SO_RCVBUF;  // have space for more data
 }
 
 bool Adaptation::Icap::Xaction::doneReading() const