svc_tp_create Subroutine

Purpose

Creates a server handle for the specified transport.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
SVCXPRT *svc_tp_create(dispatch, prog, vers, nconf);
void (*dispatch)(struct svc_req*, SVCXPRT*);
const rpcprog_t prog;
const rpcvers_t vers; 
const struct netconfig *nconf;

Description

The subroutine is an intermediate-level API for transport-independent remote procedure calls (TI_PRC). This subroutine creates and returns a service handle for the transport specified by nconf parameter. The subroutine also registers a server with the RPCBIND service. When a request arrives for the specified program and version, a subroutine specified by the dispatch parameter is called. Call the svc_run subroutine so that the server can listen to the requests from clients.

Parameters

Item Description
dispatch Specifies the subroutine that is called when a service request arrives.
prog Specifies the program number.
vers Specifies the version number.
nconf Indicates a type of transport.

Return Values

Item Description
a service handle successful
NULL unsuccessful

Examples

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

#define PROG 0x3fffffffL
#define VERS 0x1L

static void sample_dispatch();

main()
{
    SVCXPRT *svc_handle; /* server handle */
    struct netconfig *nconf; /* transport type */

    /* get transport type */ 
    nconf = getnetconfigent("tcp");
    if (nconf == (struct netconfig *) NULL)
    {
         fprintf(stderr, "getnetconfigent failed.\n");
         exit(EXIT_FAILURE);
    }
      
    /* create service handle and register with RPCBIND service */

    if((svc_handle=svc_tp_create(sample_dispatch, PROG, VERS, nconf))==(SVCXPRT *)NULL)
    {
         fprintf(stdout,"Error in svc_tp_create!");
         exit(EXIT_FAILURE);
    }
  
    svc_run();
    return 0;
} 

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

     /* code for dispatch routine  */

}