From: robert Date: Wed, 20 Dec 2006 19:25:38 +0000 (+0000) Subject: fixed a problem with read buffer resizing in TNonblockingServer X-Git-Tag: 0.2.0~1572 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=79511192f15a6a68a8c5f0ad944e528c7a5ccd61;p=common%2Fthrift.git fixed a problem with read buffer resizing in TNonblockingServer reviewed: mcslee revert: yes test: send a large message to a nonblocking server git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664900 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp index a7c8393d..9fb5c232 100644 --- a/lib/cpp/src/server/TNonblockingServer.cpp +++ b/lib/cpp/src/server/TNonblockingServer.cpp @@ -37,13 +37,9 @@ void TConnection::workSocket() { // It is an error to be in this state if we already have all the data assert(readBufferPos_ < readWant_); - // How much space is availble, and how much will we fetch - uint32_t avail = readBufferSize_ - readBufferPos_; - uint32_t fetch = readWant_ - readBufferPos_; - // Double the buffer size until it is big enough - if (fetch > avail) { - while (fetch > avail) { + if (readWant_ > readBufferSize_) { + while (readWant_ > readBufferSize_) { readBufferSize_ *= 2; } readBuffer_ = (uint8_t*)realloc(readBuffer_, readBufferSize_); @@ -55,6 +51,7 @@ void TConnection::workSocket() { } // Read from the socket + uint32_t fetch = readWant_ - readBufferPos_; int got = recv(socket_, readBuffer_ + readBufferPos_, fetch, 0); if (got > 0) {