From: Amos Jeffries Date: Fri, 23 Jan 2015 07:43:10 +0000 (-0800) Subject: Review changes for I/O buffer conversion X-Git-Tag: merge-candidate-3-v1~240^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5867ac791c02093406be210af85fed66949415a8;p=thirdparty%2Fsquid.git Review changes for I/O buffer conversion --- diff --git a/src/clients/Client.cc b/src/clients/Client.cc index 8ae2bc5b90..b663ff2554 100644 --- a/src/clients/Client.cc +++ b/src/clients/Client.cc @@ -974,12 +974,11 @@ Client::storeReplyBody(const char *data, ssize_t len) } 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 @@ -995,19 +994,14 @@ Client::needBufferSpace(const SBuf &readBuf, const size_t minSpace) const * 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 diff --git a/src/clients/Client.h b/src/clients/Client.h index 2c1ea94936..ba9650d1d8 100644 --- a/src/clients/Client.h +++ b/src/clients/Client.h @@ -143,10 +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 + /// \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); diff --git a/src/http.cc b/src/http.cc index 15debce102..7938e18912 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1140,7 +1140,7 @@ readDelayed(void *context, CommRead const &) 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); @@ -1156,8 +1156,8 @@ HttpStateData::readReply(const CommIoCbParams &io) 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 @@ -1546,9 +1546,9 @@ HttpStateData::maybeReadVirginBody() } // 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; }