cpp Directive
rpcgen supports C preprocessing features. rpcgen defaults to use /usr/ccs/lib/cpp as the C preprocessor. If that fails, rpcgen tries to use /lib/cpp. You can specify a library containing a different cpp to rpcgen with the -Y flag.
For example, if /usr/local/bin/cpp exists, you can specify it to rpcgen as follows:
rpcgen -Y /usr/local/bin test.x |
Compile-Time Flags
This section describes the rpcgen options available at compile time. The following table summarizes the options that are discussed in this section.
Table 3-2 rpcgen Compile-Time Flags
Option | Flag | Comments |
---|---|---|
-a, -Sc, -Ss, -Sm | See Table 3-3 | |
-N | Also called Newstyle mode | |
-C | Often used with the -N option | |
-M | For use in multithreaded environments | |
-A | -A also turns on -M option | |
-b | TI-RPC library is default | |
-i | Uses five packed elements as default, but other number can be specified |
Compile-Time Client and Server Templates
rpcgen generates sample code for the client and server sides. Use the options described in the following table to generate the desired templates.
Table 3-3 rpcgen Template Selection Flags
Flag | Function |
---|---|
Generates all template files | |
Generates client-side template | |
Generates server-side template | |
Generates makefile template |
The files can be used as guides by filling in the missing parts. These files are in addition to the stubs generated.
A C-style mode server template is generated from the add.x source by the command rpcgen -N -Ss -o add_server_template.c add.x
The result is stored in the file add_server_template.c. A C-style mode, client template for the same add.x source is generated with the command rpcgen -N -Sc -o add_client_template.c add.x
The result is stored in the file add_client_template.c. A makefile template for the same add.x source is generated with the command rpcgen -N -Sm -o mkfile_template add.x
The result is stored in the file mkfile_template. It can be used to compile the client and the server. The -a flag, used in the command rpcgen -N -a add.x, generates all three template files. The client template is stored in add_client.c, the server template in add_server.c, and the makefile template inmakefile.a. If any of these files already exists, rpcgen displays an error message and exits.
Note - When you generate template files, give them new names to avoid the files being overwritten the next time rpcgen is executed.
Compile-Time C-style Mode
Also called Newstyle mode, the -N flag causes rpcgen to produce code in which arguments are passed by value and multiple arguments are passed without a struct. These changes enable RPC code that is more like C and other high-level languages. For compatibility with existing programs and make files, the previous standard mode of argument passing is the default. The following examples demonstrate the new feature. The source modules for both modes, C-style and default, are shown in Example 3-8 and Example 3-9 respectively.
Example 3-8 C-style Mode Version of add.x
Example 3-9 Default Mode Version of add.x
The next four examples show the resulting client-side templates.
Example 3-10 C-style Mode Client Stub for add.x
The following code example shows how the default mode code differs from C-style mode code.
Example 3-11 Default Mode Client
arg.first = atoi(argv[2]); arg.second = atoi(argv[3]); /* * invoke remote procedure -- note * that a pointer to the argument has * to be passed to the client stub */ result = add_1(&arg, clnt); |
The server-side procedure in C-style mode is shown in the following example.
Example 3-12 C-style Mode Server
#include "add.h" int * add_1(arg1, arg2, rqstp) int arg1; int arg2; struct svc_req *rqstp; { static int result; result = arg1 + arg2; return(&result); } |