The server program using the simplified interface is straightforward. The server calls rpc_reg() to register the procedure to be called. It then calls svc_run(), the RPC library's remote procedure dispatcher, to wait for requests to arrive.
rpc_reg() has the following arguments:
rpc_reg ( rpcprog_t prognum /* Server program number */ rpcvers_t versnum /* Server version number */ rpcproc_t procnum /* server procedure number */ char *procname /* Name of remote function */ xdrproc_t inproc /* Filter to encode arg */ xdrproc_t outproc /* Filter to decode result */ char *nettype /* For transport selection */ );
svc_run() invokes service procedures in response to RPC call messages. The dispatcher in rpc_reg() decodes remote procedure arguments and encodes results, using the XDR filters specified when the remote procedure was registered. Some notes about the server program include:
Most RPC applications follow the naming convention of appending a _1 to the function name. The sequence _n is added to the procedure names to indicate the version number n of the service.
The argument and result are passed as addresses. This is true for all functions that are called remotely. Passing NULL as a result of a function means that no reply is sent to the client, because NULL indicates that there is no reply to send.
The result must exist in static data space because its value is accessed after the actual procedure has exited. The RPC library function that builds the RPC reply message accesses the result and sends the value back to the client.
Only a single argument is allowed. If there are multiple elements of data, they should be wrapped inside a structure that can then be passed as a single entity.
The procedure is registered for each transport of the specified
type. If the type parameter is (char *)NULL
, the procedure is
registered for all transports specified in NETPATH.