📄 simp.x
字号:
/* Protocol definition file for a simple RPC application *//* There are 2 remote procedures - an add procedure and a subtract procedure. Each must be called with a single parameter, a structure that holds 2 integers. The return value of each procedure is an int. Notice that I can put comments in the protocol definition file!*//* I can also put defines in here - and use them, although they willnot show up in the .h file produced by rpcgen. */#define VERSION_NUMBER 1/* If I want to put something explicitly in the .h file produced by rpcgen I can start it with %:*/%#define foo 127/* rpcgen just strips the '%' and puts the rest in the .h file *//* here is the definition of the data type that will be passed to both of my remote procedures */struct operands { int x; int y;};/* note that this data type will be defined in the .h file produced by rpcgen. AND it will be typedef'd as well, so I can refer to it as type 'operands', I don't need to use 'struct operands'. *//* OK - here is the real stuff - the program, version and proceduredefinitions. Remember this is not C, although it looks similar */program SIMP_PROG { version SIMP_VERSION { int ADD(operands) = 1; int SUB(operands) = 2; } = VERSION_NUMBER;} = 555555555;/* This defines the RPC program number as 555555555, although within theclient and server code I can just refer to it as SIMP_PROG. In other words,rpcgen will put this line in the .h file:#define SIMP_PROG 555555555The version number is 1, but I can use SIMP_VERSION.The remote procedure numbers are 1 for the add routine and 2 for thesubtract routine, although I can use the symbolic constants ADD and SUB.------------------------------On the client side, a stub will be generated in simp_clnt.c for eachof the remote procedures. The stub prototype for the add procedure looks likethis:int * add_1(operands *, CLIENT *);the "add" part of the name comes from the ADD in the protocoldefinition. the "_1" indicates the version number (if we set theversion to 100, the stub name would be "add_100").When we call this routine in the client, this stub takes care of all the RPC stuff for us, all we have to do is give it the addressof an operands structure with the x and y fields set, and an RPC handlethat is already established (the CLIENT * arg).If this isn't easy enough - just do this:rpcgen -C -Sc simp.xthe -C tells rpcgen to output ANSI C code (not K&R).the -Sc tells rpcgen to output sample client code that makes acall to each of the remote procedures, you can take thiscode and adjust it to your needs.---------------------------------On the server side, rpcgen creates the file simp_svc.h that includesa main() and an RPC dispatch routine. All we need to supply is theactual remote procedure subroutines. The server expects these routinesto have prototypes like this:int *add_1_svc(operands*, struct svc_req *);int *sub_1_svc(operands*, struct svc_req *);We need to write these routines, and include them in the link usedto create the server executable. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -