If we want to realize RPC (Remote Procedure Call), we have to build the RPC server & RPC client.
So in this blog, I will show you the main functions in code that could be used according to our project(The RPC service between ARM & ATOM) when you construct the RPC service.
(the following content just show you some function prototype,for more details about the following functions, you can refer to https://linux.die.net/)
RPC Server:
When we build the server for RPC, the following functions will always be used, and I am introducing them as the sequence that they are executed in source code.
1. boot_t pmap_unset( unsigned long prognum, unsigned long versnum);
this port map function is used to destroy all mapping between the triple [prognum,versnum,*]& ports on machine.
2. SVCXPRT svctcp_create(int sock, unsigned int send_buf_size, unsignedint recv_buf_size);
create the socket.
3. boot_t svc_register(SVCXPRT *xprt, unsigned long prognum,
unsigned long versnum,
void(*dispatch)(svc_req*, SVCXPRT *),
unsignedlong protocol);
*xprt :RPC service transport handle.
4. svc_getargs(SVCXPRT*xprt, xdrproc_t inproc, char *in);
5. svc_sendreply (SVCXPRT *xprt, xdrproc_t outproc, char *out);
6. svc_freeargs (SVCXPRT *xprt, xdrproc_t inproc, char *in);
7. void svc_run(void);
wait for RPC request to call appropriate service by svc_getreq
RPC Client:
RPC client looks like a trigger to enable the RPC servicer to implement some function, which can be conclude as three parts as follows:
a. RPC register
b. RPC request
c. RPC close
And their respectively main function prototypes are:
1. CLIENT *clnt_create(char *remoteHostIPaddr,
unsignedlong prog,
unsignedlong vers,
char*proto);
2. enum clnt_stat clnt_call (CLIENT*clnt, unsigned long prog,
xdrproc_t inproc,char *in,
xdrproc_t outproc, char *out,
struct timeval tout);
clnt: created by clnt_create
prog: the function ID you define
inproc: the program used to encode the procedure’s parameters
outproc: the program used to decode the procedure’s result
in: the address of input argument
out: the address of output result
3. clnt_destroy(CLIENT * clnt);
a macro that destroys the client’s RPC handle & it will also close the associated opened socket.
Conclusion:
After I introduce the RPC service’s main function prototype,you will find that if you want to build RPC service successfully, you should take code, functions and network into consideration, then you could achieve your goal.