}
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
* 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
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);
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);
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
}
// 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;
}