svc_dg_enablecache Subroutine

Purpose

Allocates the duplicate request cache for the service endpoint.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int svc_dg_enablecache(xprt, cachesz )
SVCXPRT *xprt;
const uint_t cachesz;

Description

This subroutine allocates the duplicate request cache for the RPC service handle specified by the xprt parameter that can hold cache entries whose number are specified by the cachesz parameter. Request caching is useful for operations that cannot be performed twice with the same result. When the cache mechanism is enabled, the mechanism cannot be disabled.

Parameters

Item Description
xprt Indicates the RPC service handle.
cachesz Indicates the number of cache entries.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

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

#define PROG 0x3fffffffL
#define VERS 0x1L

static void sample_dispatch();

main()
{

     SVCXPRT *svc_handle;
     struct netconfig *nconf;
            
     svc_unreg(PROG,VERS);

     /* Get desired transport type */
     nconf = getnetconfigent("tcp");
     if(nconf == NULL)
     {
          fprintf(stderr,"\nError in getnetconfigent!\n");
          exit(EXIT_FAILURE);
     }

     /* Create svc_handle */
     svc_handle = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
     if(svc_handle == (SVCXPRT *)NULL)
     {
           fprintf(stdout,"Error in svc_tli_create!");
           exit(EXIT_FAILURE);
     }               

     /* Register dispatch routine for prog and vers with RPCBIND service */

     if(svc_reg(svc_handle, PROG, VERS, sample_dispatch,nconf) == 0)
     {
           fprintf(stdout,"Error in svc_reg!");
           exit(EXIT_FAILURE);
     }
             
     /* This subroutine allocates duplicate cache */
     if( svc_dg_enablecache(svc_handle,5) == 0)
     {
           fprintf(stdout,"Error in svc_dg_enablecache!");
           exit(EXIT_FAILURE);
     }

     svc_run();

     fprintf(stderr,"\nError in svc_run!\n");
     exit(EXIT_FAILURE);
}

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

}