我正在寻找C ++异步客户端和非阻塞C ++服务器实现。我在apache中看到了一些邮件存档,但活动是在2009年末。想知道它是否支持最新的节俭。我正在使用C ++代码的cob_style选项,但生成的代码无法编译。 非常感谢任何帮助, 谢谢
答案 0 :(得分:4)
对于服务器,您在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();