|
|
It is sometimes useful for programs to have access to dispatch tables used by the RPC package. For example, the server dispatch routine may need to check authorization and then invoke the service routine; or a client library may want to deal with the details of storage management and XDR data conversion.
When invoked with the -T option, rpcgen generates RPC dispatch tables for each program defined in the protocol description file, proto.x, in the file proto_tbl.i. For sample protocol description file, dir.x, given in ``Generating XDR routines with rpcgen'', a dispatch table file created by rpcgen would be called dir_tbl.i. The suffix .i stands for ``index.''
Each entry in the dispatch table is a struct rpcgen_table, defined in the header file proto.h as follows:
struct rpcgen_table { char *(*proc)(); xdrproc_t xdr_arg; unsigned len_arg; xdrproc_t xdr_res; unsigned len_res; };Here:
An example of how to locate a procedure in the dispatch tables is shown by the routine find_proc():
struct rpcgen_table * find_proc(proc) long proc; { if (proc >= dirprog_1_nproc) /* error */ else return (&dirprog_1_table[proc]); }Each entry in the dispatch table contains a pointer to the corresponding service routine. However, that service routine is usually not defined in the client code. To avoid generating unresolved external references, and to require only one source file for the dispatch table, the rpcgen service routine initializer is RPCGEN_ACTION(proc_ver).
This way, the same dispatch table can be included in both the client and the server. Use the following definition when compiling the client:
#define RPCGEN_ACTION(routine) 0and use this definition when compiling the server:
#define RPCGEN_ACTION(routine) routine