More boosification of thrift driver, server, transport and protocol code
Modified TestServer to use thread-pool manager
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664737 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TThreadPoolServer.cc b/lib/cpp/src/server/TThreadPoolServer.cc
index 2d6290c..d53d174 100644
--- a/lib/cpp/src/server/TThreadPoolServer.cc
+++ b/lib/cpp/src/server/TThreadPoolServer.cc
@@ -12,87 +12,78 @@
using namespace facebook::thrift::concurrency;
using namespace facebook::thrift::transport;
-class TThreadPoolServer : public TServer {
-
- class Task: public Runnable {
+class TThreadPoolServer::Task: public Runnable {
- TProcessor* _processor;
- TTransport* _transport;
- TBufferedTransport _bufferedTransport;
+ shared_ptr<TProcessor> _processor;
+ shared_ptr<TTransport> _transport;
+ shared_ptr<TBufferedTransport> _bufferedTransport;
- public:
+public:
- Task(TProcessor* processor,
- TTransport* transport) :
- _processor(processor),
- _transport(transport),
- _bufferedTransport(_transport) {
- }
-
- ~Task() {
- delete _transport;
- }
-
- void run() {
-
- while(true) {
-
- try {
- _processor->process(&_bufferedTransport);
-
- } catch (TTransportException& ttx) {
-
- break;
-
- } catch(...) {
-
- break;
- }
- }
-
- _bufferedTransport.close();
- }
- };
-
- TThreadPoolServer(TProcessor* processor,
- TServerOptions* options,
- TServerTransport* serverTransport,
- ThreadManager* threadManager) :
- TServer(processor, options),
- serverTransport_(serverTransport),
- threadManager_(threadManager) {
+ Task(shared_ptr<TProcessor> processor,
+ shared_ptr<TTransport> transport) :
+ _processor(processor),
+ _transport(transport),
+ _bufferedTransport(new TBufferedTransport(transport)) {
}
+
+ ~Task() {}
- ~TThreadPoolServer() {}
-
- protected:
-
- TServerTransport* serverTransport_;
- ThreadManager* threadManager_;
-
void run() {
-
- try {
- // Start the server listening
- serverTransport_->listen();
- } catch (TTransportException& ttx) {
- cerr << "TThreadPoolServer::run() listen(): " << ttx.getMessage() << endl;
- return;
- }
-
- // Fetch client from server
-
- while (true) {
-
+
+ while(true) {
+
try {
-
- threadManager_->add(shared_ptr<Task>(new TThreadPoolServer::Task(processor_, serverTransport_->accept())));;
-
+ _processor->process(_bufferedTransport);
+
} catch (TTransportException& ttx) {
+
+ break;
+
+ } catch(...) {
+
break;
}
}
+
+ _bufferedTransport->close();
}
};
+
+TThreadPoolServer::TThreadPoolServer(shared_ptr<TProcessor> processor,
+ shared_ptr<TServerOptions> options,
+ shared_ptr<TServerTransport> serverTransport,
+ shared_ptr<ThreadManager> threadManager) :
+ TServer(processor, options),
+ serverTransport_(serverTransport),
+ threadManager_(threadManager) {
+}
+
+TThreadPoolServer::~TThreadPoolServer() {}
+
+void TThreadPoolServer::run() {
+
+ try {
+ // Start the server listening
+ serverTransport_->listen();
+ } catch (TTransportException& ttx) {
+ cerr << "TThreadPoolServer::run() listen(): " << ttx.getMessage() << endl;
+ return;
+ }
+
+ // Fetch client from server
+
+ while (true) {
+
+ try {
+
+ threadManager_->add(shared_ptr<TThreadPoolServer::Task>(new TThreadPoolServer::Task(processor_,
+ shared_ptr<TTransport>(serverTransport_->accept()))));
+
+ } catch (TTransportException& ttx) {
+ break;
+ }
+ }
+}
}}} // facebook::thrift::server