C ++ thrift实现作为一个类

时间:2012-11-29 16:10:45

标签: c++ boost thrift

所以我试图将大多数教程提供的以下C ++ thrift服务器实现转换为类形式:

int port = 9090;
  shared_ptr<SomethingHandler> handler(new SomethingHandler());
  shared_ptr<TProcessor> processor(new SomethingProcessor(handler));
  shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());

  TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);

为此,我创建了所有shared_ptrs和TSimpleServer成员,但是我在启动分配时遇到了麻烦。

在initlization列表中构建shared_ptr似乎会导致badmalloc错误,因此我的解决方法是将它们声明为成员并通过asisgnment初始化:

 handler = shared_ptr<type>(new Type). 

这里的问题是TSimpleServer没有赋值void的赋值运算符或构造函数,因此它需要依赖于构造函数时构造的shared_ptrs,因此可以构造它。
有什么想法,我在这里缺少什么?

更多psuedocode:

class myclass {
 int port;
 shared_ptr<MyHandlder> handler;
 shared_ptr<TProcessor> processor;
 shared_ptr<TServerTransport> serverTransport;
 shared_ptr<TTransportFactory>  transportFactory;
 shared_ptr<TProtocolFactory> protocolFactory;
 TSimpleServer server;

  public: 
        explicit myclass(): port(9090), handler(new MyHandler()), processor(new MyProcessor(handler)), serverTransport(new TServerSocket(port)), transportFactory(new TBufferedTransportFactory()), protocolFactory(new TBinaryProtocolFactory()), server(processor, serverTransport, transportFactory, protocolFactory) { }

 int start () { server.serve() }

0 个答案:

没有答案