svc_create Subroutine

Purpose

Creates remote procedure call (RPC) service handles for all specified transports.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int svc_create(dispatch, prog, vers, nettype);
void (*dispatch) (const struct svc_req*, const SVCXPRT*);
const rpcprog_t prog;
const rpcvers_t vers;
const char *nettype;

Description

This subroutine is a top-level API for transport-independent remote procedure calls (TI_PRC), giving you greater control over communication parameters. This subroutine creates RPC service handles and registers with RPC service package with the specified program and version for all transports of the class specified by the nettype parameter. If the value of the nettype parameter is NULL, the subroutine searches transports in the NETPATH environment variable from left to right. If the value of the NETPATH variable is also NULL or unset, the subroutine searches in the netconfig database from top to bottom. After creating the handle, call the svc_run subroutine that waits for a service request to arrive. When a service request from the client for the specified program and version arrives, a dispatch subroutine is called.

Parameters

Item Description
dispatch Specifies a subroutine that is called when a service request arrives.
prog Represents the program number.
vers Represents the version number.
nettype Defines a class of transports that can be used for a particular application.

Return Values

Item Description
the number of RPC service handles that are created successful
0 unsuccessful

Examples

#include <stdlib.h>
#include <rpc/rpc.h>

#define PROG 0x3fffffffL
#define VERS 0x1L


static void sample_dispatch();
    
main()
{
      char *nettype;
      int no_of_handles;

      /* initialize transport type */
      nettype = "tcp";                 
 
      /* Create RPC service handle and register with RPCBIND service */

      if((no_of_handles = svc_create(sample_dispatch, PROG, VERS,nettype)) == 0)
      {
            fprintf(stdout,"Error in svc_create!");
            exit(EXIT_FAILURE);
      }
  
      svc_run();

      return 0;
} 

/* following is the sample dispatch routine*/
static void sample_dispatch(struct svc_req *request, SVCXPRT *xprt)
{

     /*   dispatch routine code  */

       }