From 79511192f15a6a68a8c5f0ad944e528c7a5ccd61 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 20 Dec 2006 19:25:38 +0000 Subject: [PATCH] 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 --- lib/cpp/src/server/TNonblockingServer.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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) { -- 2.17.1