| 63 | }; |
| 64 | |
| 65 | int main(int argc, char *argv[]) { |
| 66 | // Parse gflags. We recommend you to use gflags as well. |
| 67 | google::ParseCommandLineFlags(&argc, &argv, true); |
| 68 | |
| 69 | THRIFT_STDCXX::shared_ptr<EchoServiceHandler> handler(new EchoServiceHandler()); |
| 70 | #if THRIFT_STDCXX != std |
| 71 | // For thrift version less than 0.13.0 |
| 72 | THRIFT_STDCXX::shared_ptr<apache::thrift::concurrency::PosixThreadFactory> thread_factory( |
| 73 | new apache::thrift::concurrency::PosixThreadFactory( |
| 74 | apache::thrift::concurrency::PosixThreadFactory::ROUND_ROBIN, |
| 75 | apache::thrift::concurrency::PosixThreadFactory::NORMAL, 1, false)); |
| 76 | #else |
| 77 | // For thrift version greater equal than 0.13.0 |
| 78 | THRIFT_STDCXX::shared_ptr<apache::thrift::concurrency::ThreadFactory> thread_factory( |
| 79 | new apache::thrift::concurrency::ThreadFactory(false)); |
| 80 | #endif |
| 81 | |
| 82 | THRIFT_STDCXX::shared_ptr<apache::thrift::server::TProcessor> processor( |
| 83 | new example::EchoServiceProcessor(handler)); |
| 84 | THRIFT_STDCXX::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocol_factory( |
| 85 | new apache::thrift::protocol::TBinaryProtocolFactory()); |
| 86 | THRIFT_STDCXX::shared_ptr<apache::thrift::transport::TTransportFactory> transport_factory( |
| 87 | new apache::thrift::transport::TBufferedTransportFactory()); |
| 88 | THRIFT_STDCXX::shared_ptr<apache::thrift::concurrency::ThreadManager> thread_mgr( |
| 89 | apache::thrift::concurrency::ThreadManager::newSimpleThreadManager(2)); |
| 90 | |
| 91 | thread_mgr->threadFactory(thread_factory); |
| 92 | |
| 93 | thread_mgr->start(); |
| 94 | |
| 95 | #if defined(_THRIFT_STDCXX_H_) || !defined (_THRIFT_VERSION_LOWER_THAN_0_11_0_) |
| 96 | THRIFT_STDCXX::shared_ptr<apache::thrift::transport::TNonblockingServerSocket> server_transport = |
| 97 | THRIFT_STDCXX::make_shared<apache::thrift::transport::TNonblockingServerSocket>(FLAGS_port); |
| 98 | |
| 99 | apache::thrift::server::TNonblockingServer server(processor, |
| 100 | transport_factory, transport_factory, protocol_factory, |
| 101 | protocol_factory, server_transport); |
| 102 | #else |
| 103 | apache::thrift::server::TNonblockingServer server(processor, |
| 104 | transport_factory, transport_factory, protocol_factory, |
| 105 | protocol_factory, FLAGS_port); |
| 106 | #endif |
| 107 | server.serve(); |
| 108 | return 0; |
| 109 | } |