在c++中使用rpcgen

Using rpcgen with C++

本文关键字:rpcgen c++      更新时间:2023-10-16

我正在使用rpcgen库创建一个应用程序,我必须在服务器端使用hashmap。是否建议使用STL库(或任何c++代码)与rpcgen?我试过用g++编译文件,它可以工作。或者在坚持使用C语言的同时,实现链表之类的东西而不是hashmap(我假设复杂性不是问题)会更好吗?

我的输入文件是
struct intpair {
        int a;
        int b;
};
program ADD_PROG {
        version ADD_VERS {
                int ADD(intpair) = 1;
        } = 1;
} = 0x23451111;
从http://www.cs.rutgers.edu/

(~ pxk/罗格斯/notes/rpc/index . html)。

我想在服务器端使用hashmap。我尝试在我的服务器端文件中做这样的事情:

#include "add.h"
#include <map>
#include <string>
int *
add_1_svc(intpair *argp, struct svc_req *rqstp)
{
    std::map<std::string, int> voteList;
    static int result;
    std::string s = "Aa";
    voteList.insert(std::pair<std::string, int> ("ABC", 100));
    printf("Add calledn");
    return &result;
}

,它可以工作。但是我必须重命名文件并使用g++。

看起来c++ STL组件不会通过您正在实现的接口"泄漏",所以它应该都很好。需要注意的一件事是异常安全:您可能希望添加一个顶级的try/catch块来将任何异常转换为适当的错误。