我正在尝试创建一个TNonblockingServer并使用registerEvents方法注册用户创建的事件库。 registerEvents方法抛出一个使程序崩溃的断言。我正在粘贴服务器代码。
int main(int ac, char **av)
{
try
{
boost::shared_ptr<AdderHandler> handler(new AdderHandler());
boost::shared_ptr<TProcessor> processor(new AdderProcessor(handler));
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TNonblockingServer server(processor, protocolFactory, 9090);
//create a foreign event loop
event_base *eb = event_base_new();
struct event * es = evsignal_new(eb, SIGTERM, &sigtermHandler, eb);
evsignal_add(es, NULL);
//tell thrift to use it.
server.registerEvents(eb);
//Finally called serve
server.serve();
}
catch(TTransportException &ex)
{
std::cerr<<"server exited with exception:"<<ex.what();
return -1;
}
return 0;
}
错误消息:
Thrift: Wed Dec 10 23:12:47 2014 TNonblockingServer: Serving on port 9090, 1 io threads.
Thrift: Wed Dec 10 23:12:47 2014 TNonblockingServer: using libevent 2.0.21-stable method epoll
Thrift: Wed Dec 10 23:12:47 2014 TNonblocking: IO thread #0 registered for listen.
Thrift: Wed Dec 10 23:12:47 2014 TNonblocking: IO thread #0 registered for notify.
server: src/thrift/server/TNonblockingServer.cpp:1199: void apache::thrift::server::TNonblockingServer::registerEvents(event_base*): Assertion `ioThreads_.empty()' failed.
Aborted (core dumped)
答案 0 :(得分:1)
这是TNonblockingServer中的一个错误,serve()方法在开始时为使用事件库注册一个NULL。注释掉TNonblockingServer.cpp:1257这一行,解决了这个问题。但我不太清楚我搞砸了什么。