Daniel Krom
Daniel Krom

Reputation: 10068

rpcgen adds _svc extension

Creating a simple server-client program using rpcgen.

I'm writing this .x file:

program REMOTE_PROG {
    version MSG_RCV {
        int STRLEN(string)      = 1;
        double SQUARE(double *) = 2;
        int NUM_OF_DEV(int *)   = 3;

    } = 1;
} = 99;

executing with rpcgen file.x -> generates file_svc.c.

in the file_svc.c file, for some reason, it generates each function case with _svc extension:

case STRLEN:
    xdr_argument = xdr_wrapstring;
    xdr_result = xdr_int;
    local = (char *(*)()) strlen_1_svc; //<--_SVC
    break;

and when I try to compile the server after implementing the functions

int * strlen_1(char **, CLIENT *);

the compiler raises that error:

"_strlen_1_svc", referenced from:
  _remote_prog_1 in file_svc-8501b7.o
ld: symbol(s) not found for architecture x86_64

But if I'll delete that auto generated _svc extension,local = (char *(*)()) strlen_1; //no _svc the program will compile successfully.

Why does this happen? why does the rpcgen adds the _svc extension to the functions and am I doing something wrong when I delete the _svc?


P.S same error also for square and num_of_dev functions, gave only strlen for example.

Thanks!

Upvotes: 0

Views: 220

Answers (2)

Joster
Joster

Reputation: 369

After execution of rpcgen ex7.x you should have created the client and server stubs ex7_clnt.c and ex7_svc.c and also a header file ex7.h

In the header file you will have declared both functions strlen_1 and strlen_1_svc, they have to have different names as they are different functions: first one is on the client side and invokes the second one on the server side through RPC call.

Upvotes: 0

nos
nos

Reputation: 229304

That's the convention, the _svc is short for service.

Your server needs to implement the service function, that is the strlen_1_svc function.

Your client calls the strlen_1 function. rpcgen + the RPC library does all the inbetween - it generates code for strlen_1 used by the client which will serialize the data and transfer it to the server, where an event loop dispatches the call to your code in the strlen_1_svc function.

Upvotes: 1

Related Questions