-- Nonblocking server changes to allow logging
Summary:
-- the constructor needs to accept a transport factory
-- TConnection close() needs to close factor generated transports
Reviewed By: Mark Slee
Test Plan: Tested with search redologger
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664930 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h
index 11b58b1..c8bfcb5 100644
--- a/lib/cpp/src/server/TNonblockingServer.h
+++ b/lib/cpp/src/server/TNonblockingServer.h
@@ -50,12 +50,23 @@
void handleEvent(int fd, short which);
public:
- TNonblockingServer(shared_ptr<TProcessor> processor, int port) :
- TServer(processor),
+ TNonblockingServer(shared_ptr<TProcessor> processor,
+ shared_ptr<TProtocolFactory> protocolFactory,
+ int port) :
+ TServer(processor, protocolFactory),
serverSocket_(0),
port_(port),
frameResponses_(true) {}
-
+
+ TNonblockingServer(shared_ptr<TProcessor> processor,
+ shared_ptr<TProtocolFactory> protocolFactory,
+ shared_ptr<TTransportFactory> transportFactory,
+ int port) :
+ TServer(processor, protocolFactory, transportFactory),
+ serverSocket_(0),
+ port_(port),
+ frameResponses_(true) {}
+
~TNonblockingServer() {}
void setFrameResponses(bool frameResponses) {
@@ -155,6 +166,10 @@
// Transport that processor writes to
shared_ptr<TMemoryBuffer> outputTransport_;
+ // extra transport generated by transport factory (e.g. BufferedRouterTransport)
+ shared_ptr<TTransport> factoryInputTransport_;
+ // shared_ptr<TTransport> factoryOutputTransport_;
+
// Protocol encoder
shared_ptr<TProtocol> outputProtocol_;
@@ -183,7 +198,8 @@
public:
// Constructor
- TConnection(int socket, short eventFlags, TNonblockingServer *s) {
+ TConnection(int socket, short eventFlags, TNonblockingServer *s,
+ shared_ptr<TTransportFactory> transportFactory) {
readBuffer_ = (uint8_t*)malloc(1024);
if (readBuffer_ == NULL) {
throw new facebook::thrift::TException("Out of memory.");
@@ -191,15 +207,11 @@
readBufferSize_ = 1024;
// Allocate input and output tranpsorts
+ // these only need to be allocated once per TConnection (they don't need to be
+ // reallocated on init() call)
inputTransport_ = shared_ptr<TMemoryBuffer>(new TMemoryBuffer(readBuffer_, readBufferSize_));
outputTransport_ = shared_ptr<TMemoryBuffer>(new TMemoryBuffer());
-
- // Create protocol
- std::pair<shared_ptr<TProtocol>,shared_ptr<TProtocol> > iop;
- iop = s->getProtocolFactory()->getIOProtocols(inputTransport_, outputTransport_);
- inputProtocol_ = iop.first;
- outputProtocol_ = iop.second;
-
+
init(socket, eventFlags, s);
}