4

我正在寻找一个 C++ 异步客户端和非阻塞 C++ 服务器实现。我在 apache 中看到了一些邮件存档,但活动是在 2009 年末。想知道它是否在最新的 thrift 中支持。我对 C++ 代码使用 cob_style 选项,但生成的代码无法编译。将不胜感激任何帮助,谢谢

4

1 回答 1

5

对于服务器,您有 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();
于 2012-04-29T10:35:32.277 回答