DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with Remote Procedure Calls (RPC)

Dispatch tables

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:

proc
is a pointer to the service routine

xdr_arg
is a pointer to the input (argument) xdr_ routine

len_arg
is the length in bytes of the input argument

xdr_res
is a pointer to the output (result) xdr_ routine

len_res
is the length in bytes of the output result
The table, named dirprog_1_table for the dir.x example, is indexed by procedure number. The variable dirprog_1_nproc contains the number of entries in the table.

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)	0
and use this definition when compiling the server:
   #define RPCGEN_ACTION(routine)	routine

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004