如何把thrift服务端handler作为动态库使用?
我把thrift服务端handler作为DLL导出,然后我写了一个动态添加服务的主程序,用户输入动态库路径,主程序有个线程会把服务动态库handler注册到全局变量thrift的TMultiplexedProcessor(TMultiplexedProcessor->registerProcessor),但是当客户端访问时却提示服务未注册!请问大神们哪里出了问题?该如何动态添加服务?我的代码如下
==========================================================================================
int addUserServiceDLLFun(std::string &serviceName,std::string &dllName){
HINSTANCE hdll;
hdll=LoadLibrary(dllName.c_str());
std::cout<<"hdll:"<<hdll<<std::endl;
if(hdll==NULL){
FreeLibrary(hdll);
}
PointerDllServiceFun pdllServiceFun;
pdllServiceFun = (PointerDllServiceFun)GetProcAddress(hdll,"getTProcessorHandler");//获取函数地址
std::cout<<"pdllServiceFun:"<<pdllServiceFun<<std::endl;
if(pdllServiceFun==NULL){
FreeLibrary(hdll);
return -1;
}
boost::shared_ptr<TProcessor> tprocessor=pdllServiceFun();
globeProcessor->registerProcessor(serviceName,tprocessor);
return 1;
}
==========================================================================================
extern "C" _declspec(dllexport) boost::shared_ptr<TProcessor> getTProcessorHandler(){
boost::shared_ptr<TProcessor> processor(new MyHelloServiceJellyProcessor(boost::shared_ptr<MyHelloServiceJellyHandler>(new MyHelloServiceJellyHandler())));
return processor;
}
==========================================================================================
void* loadUserServiceDLLFun(void* args){
std::string dllPath;
while (true){
std::cin>>dllPath;
string::size_type iPos = dllPath.find_last_of('\\')+1;
cout<< dllPath <<endl;
string filename = dllPath.substr(iPos, dllPath.length() - iPos);
cout << filename << endl;
string name = filename.substr(0, filename.rfind("."));
cout << name << endl;
string suffix_str = filename.substr(filename.find_last_of('.') + 1);
cout << suffix_str << endl;
addUserServiceDLLFun(filename,dllPath);
}
}
==========================================================================================
//main.cpp
pthread_t loadUserDllThread;
int ret = pthread_create(&loadUserDllThread, NULL,loadUserServiceDLLFun, NULL);
if (ret != 0){
cout << "pthread_create error: error_code=" << ret << endl;
}
boost::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
boost::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
boost::shared_ptr<BoostThreadFactory> threadFactory = boost::shared_ptr<BoostThreadFactory>(new BoostThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
TThreadPoolServer server(globeProcessor,
serverTransport,
transportFactory,
protocolFactory,
threadManager);
server.serve();
==========================================================================================
!!服务端报错 !!
Do you forget to call registerProcessor()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论