Search code examples
thrift

apache thrift C++ async client


I am looking for a C++ async client and nonblocking C++ server implementation. I see some mail archives in the apache but the activity is late in 2009. would like to know whether its supported in latest thrift or not. I am using the cob_style option for C++ code but the generated code does not compile. would appreciate any help, Thanks


Solution

  • for a server, you have the TNonBlockingServer implementation in C++:

    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();