2012-04-27 156 views
2

我正在尋找一個C++異步客戶端和非阻塞C++服務器實現。我在apache上看到了一些郵件存檔,但是這項活動在2009年晚了。想知道它是否支持最新的節儉。我爲C++代碼使用cob_style選項,但生成的代碼不能編譯。 希望得到任何幫助, 感謝apache thrift C++異步客戶端

回答

3

一臺服務器,你必須在C++中TNonBlockingServer實現:

using namespace ::apache::thrift; 
using namespace ::apache::thrift::protocol; 
using namespace ::apache::thrift::transport; 
using namespace ::apache::thrift::server; 
using namespace ::apache::thrift::concurrency; 


shared_ptr<MyHandler> handler(new MyHandler()); 
shared_ptr<TProcessor> processor(new (handler)); 
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); 

// using thread pool with maximum 15 threads to handle incoming requests 
shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(15); 
shared_ptr<PosixThreadFactory> threadFactory = shared_ptr<PosixThreadFactory>(new PosixThreadFactory()); 
threadManager->threadFactory(threadFactory); 
threadManager->start(); 

//create and start the server 
shared_ptr<TNonblockingServer> server = new TNonblockingServer(processor, protocolFactory, port, threadManager); 
server->serve();