2012-04-27 161 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();