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;
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
// 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;
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