mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
THRIFT-926. cpp: Revert r750153 to make way for more flexible version
r750153 caused TNonblockingServer to reset its buffers every 512 calls. A more configurable version was developed internally, so I'm reverting this rev first to avoid conflicts. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005163 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
109693c82a
commit
7197efb849
@ -246,24 +246,8 @@ void TConnection::transition() {
|
||||
case APP_READ_REQUEST:
|
||||
// We are done reading the request, package the read buffer into transport
|
||||
// and get back some data from the dispatch function
|
||||
// If we've used these transport buffers enough times, reset them to avoid bloating
|
||||
|
||||
inputTransport_->resetBuffer(readBuffer_, readBufferPos_);
|
||||
++numReadsSinceReset_;
|
||||
if (numWritesSinceReset_ < 512) {
|
||||
outputTransport_->resetBuffer();
|
||||
} else {
|
||||
// reset the capacity of the output transport if we used it enough times that it might be bloated
|
||||
try {
|
||||
outputTransport_->resetBuffer(true);
|
||||
numWritesSinceReset_ = 0;
|
||||
} catch (TTransportException &ttx) {
|
||||
GlobalOutput.printf("TTransportException: TMemoryBuffer::resetBuffer() %s", ttx.what());
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
outputTransport_->resetBuffer();
|
||||
// Prepend four bytes of blank space to the buffer so we can
|
||||
// write the frame size there later.
|
||||
outputTransport_->getWritePtr(4);
|
||||
@ -359,27 +343,11 @@ void TConnection::transition() {
|
||||
|
||||
case APP_SEND_RESULT:
|
||||
|
||||
++numWritesSinceReset_;
|
||||
|
||||
// N.B.: We also intentionally fall through here into the INIT state!
|
||||
|
||||
LABEL_APP_INIT:
|
||||
case APP_INIT:
|
||||
|
||||
// reset the input buffer if we used it enough times that it might be bloated
|
||||
if (numReadsSinceReset_ > 512)
|
||||
{
|
||||
void * new_buffer = std::realloc(readBuffer_, 1024);
|
||||
if (new_buffer == NULL) {
|
||||
GlobalOutput("TConnection::transition() realloc");
|
||||
close();
|
||||
return;
|
||||
}
|
||||
readBuffer_ = (uint8_t*) new_buffer;
|
||||
readBufferSize_ = 1024;
|
||||
numReadsSinceReset_ = 0;
|
||||
}
|
||||
|
||||
// Clear write buffer variables
|
||||
writeBuffer_ = NULL;
|
||||
writeBufferPos_ = 0;
|
||||
|
@ -626,12 +626,6 @@ enum TAppState {
|
||||
/// How far through writing are we?
|
||||
uint32_t writeBufferPos_;
|
||||
|
||||
/// How many times have we read since our last buffer reset?
|
||||
uint32_t numReadsSinceReset_;
|
||||
|
||||
/// How many times have we written since our last buffer reset?
|
||||
uint32_t numWritesSinceReset_;
|
||||
|
||||
/// Task handle
|
||||
int taskHandle_;
|
||||
|
||||
@ -706,9 +700,6 @@ enum TAppState {
|
||||
}
|
||||
readBufferSize_ = STARTING_CONNECTION_BUFFER_SIZE;
|
||||
|
||||
numReadsSinceReset_ = 0;
|
||||
numWritesSinceReset_ = 0;
|
||||
|
||||
// Allocate input and output tranpsorts
|
||||
// these only need to be allocated once per TConnection (they don't need to be
|
||||
// reallocated on init() call)
|
||||
|
@ -591,23 +591,7 @@ class TMemoryBuffer : public TVirtualTransport<TMemoryBuffer, TBufferBase> {
|
||||
str.append((char*)buf, sz);
|
||||
}
|
||||
|
||||
void resetBuffer(bool reset_capacity = false) {
|
||||
if (reset_capacity)
|
||||
{
|
||||
assert(owner_);
|
||||
|
||||
void* new_buffer = std::realloc(buffer_, defaultSize);
|
||||
|
||||
if (new_buffer == NULL) {
|
||||
throw TTransportException("Out of memory.");
|
||||
}
|
||||
|
||||
buffer_ = (uint8_t*) new_buffer;
|
||||
bufferSize_ = defaultSize;
|
||||
|
||||
wBound_ = buffer_ + bufferSize_;
|
||||
}
|
||||
|
||||
void resetBuffer() {
|
||||
rBase_ = buffer_;
|
||||
rBound_ = buffer_;
|
||||
wBase_ = buffer_;
|
||||
|
Loading…
Reference in New Issue
Block a user