How to Realize RPC?

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值