From: Amos Jeffries Date: Tue, 11 Nov 2014 13:41:59 +0000 (-0800) Subject: Extend Client API to estimate needed buffer space using an SBuf X-Git-Tag: merge-candidate-3-v1~240^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2554f0fee808ef75a88494179e1325a1dbb5757;p=thirdparty%2Fsquid.git Extend Client API to estimate needed buffer space using an SBuf 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. --- diff --git a/src/clients/Client.cc b/src/clients/Client.cc index d09833ca28..ae6502a5d3 100644 --- a/src/clients/Client.cc +++ b/src/clients/Client.cc @@ -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) { diff --git a/src/clients/Client.h b/src/clients/Client.h index 40c508e9b7..a9a75bb975 100644 --- a/src/clients/Client.h +++ b/src/clients/Client.h @@ -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);