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 a7c8393..9fb5c23 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -37,13 +37,9 @@
// 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 @@
}
// Read from the socket
+ uint32_t fetch = readWant_ - readBufferPos_;
int got = recv(socket_, readBuffer_ + readBufferPos_, fetch, 0);
if (got > 0) {