如何把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()?
阅读 1.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题