-- Change concept of protocol and transport factory
Summary:
- Transport factories now wrap around one transport
- Protocol factories now wrap around one transport (as opposed to a pair of input/output
transports)
- TServer now takes input/output transport and protocol factories
The motivation for this change is that you could concievably want to use a different protocol or
transport for input and output. An example is that incoming data is encoded using binary protocol
but outgoing data is encrypted XML (with encryption being done on the transport level).
This change should be mostly backwards compatible because the TServer classes have constructors
that take a transport factory and use that for both the input and transport factories. The only
change might be for anyone who is using the C++ client code directly i.e. instantiating
TBinaryProtocol() directly because the constructor now only accepts one transport.
Reviewed By: Slee
Test Plan: Everything compiles (for both thrift and search).
Notes:
I am going to make the same changes in all the supported languages after this...
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664940 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h
index 4ea3fa3..08ecec6 100644
--- a/lib/cpp/src/server/TNonblockingServer.h
+++ b/lib/cpp/src/server/TNonblockingServer.h
@@ -60,19 +60,31 @@
TNonblockingServer(shared_ptr<TProcessor> processor,
shared_ptr<TProtocolFactory> protocolFactory,
int port) :
- TServer(processor, protocolFactory),
+ TServer(processor),
serverSocket_(0),
port_(port),
- frameResponses_(true) {}
+ frameResponses_(true) {
+ setInputTransportFactory(shared_ptr<TTransportFactory>(new TTransportFactory()));
+ setOutputTransportFactory(shared_ptr<TTransportFactory>(new TTransportFactory()));
+ setInputProtocolFactory(protocolFactory);
+ setOutputProtocolFactory(protocolFactory);
+ }
- TNonblockingServer(shared_ptr<TProcessor> processor,
- shared_ptr<TProtocolFactory> protocolFactory,
- shared_ptr<TTransportFactory> transportFactory,
+ TNonblockingServer(shared_ptr<TProcessor> processor,
+ shared_ptr<TTransportFactory> inputTransportFactory,
+ shared_ptr<TTransportFactory> outputTransportFactory,
+ shared_ptr<TProtocolFactory> inputProtocolFactory,
+ shared_ptr<TProtocolFactory> outputProtocolFactory,
int port) :
- TServer(processor, protocolFactory, transportFactory),
+ TServer(processor),
serverSocket_(0),
port_(port),
- frameResponses_(true) {}
+ frameResponses_(true) {
+ setInputTransportFactory(inputTransportFactory);
+ setOutputTransportFactory(outputTransportFactory);
+ setInputProtocolFactory(inputProtocolFactory);
+ setOutputProtocolFactory(outputProtocolFactory);
+ }
~TNonblockingServer() {}
@@ -175,13 +187,13 @@
// extra transport generated by transport factory (e.g. BufferedRouterTransport)
shared_ptr<TTransport> factoryInputTransport_;
- // shared_ptr<TTransport> factoryOutputTransport_;
-
- // Protocol encoder
- shared_ptr<TProtocol> outputProtocol_;
+ shared_ptr<TTransport> factoryOutputTransport_;
// Protocol decoder
shared_ptr<TProtocol> inputProtocol_;
+
+ // Protocol encoder
+ shared_ptr<TProtocol> outputProtocol_;
// Go into read mode
void setRead() {
@@ -205,8 +217,7 @@
public:
// Constructor
- TConnection(int socket, short eventFlags, TNonblockingServer *s,
- shared_ptr<TTransportFactory> transportFactory) {
+ TConnection(int socket, short eventFlags, TNonblockingServer *s) {
readBuffer_ = (uint8_t*)malloc(1024);
if (readBuffer_ == NULL) {
throw new facebook::thrift::TException("Out of memory.");