Reputation: 401
I'm using the rpcgen libraries to create an application where I have to use a hashmap on the server side. Is it advisable to use the STL libraries (or any C++ code) with rpcgen? I've tried compiling the files with g++ and it works. Or would I be better off implementing something like a linked list instead of a hashmap (I'm assuming complexity is not an issue) while sticking with C?
Something like this : My input file is
struct intpair {
int a;
int b;
};
program ADD_PROG {
version ADD_VERS {
int ADD(intpair) = 1;
} = 1;
} = 0x23451111;
(from http://www.cs.rutgers.edu/~pxk/rutgers/notes/rpc/index.html).
I want to use a hashmap on the server side. I tried doing something like this in my server side file:
#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 called\n");
return &result;
}
and it works. I did have to rename the files and use g++ though.
Upvotes: 1
Views: 2234
Reputation: 249582
It looks like the C++ STL components don't "leak" through the interface you're implementing, so it should be all fine and good. One thing to be aware of is exception safety: you might want to add a top-level try/catch block to convert any exceptions into an appropriate error.
Upvotes: 2