svc_done Subroutine

Note: You can set the server in multithreaded mode using the rpc_control subroutine.

Purpose

Frees the resources allocated to service a client request.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int svc_done(xprt )
SVCXPRT *xprt;

Description

The svc_done subroutine frees the resources allocated to service a client request. The subroutine is used when the server is in the user-multithreaded mode. If used in the single-threaded mode or in the AUTO-MT mode, the subroutine has no effect. This subroutine is normally called in a service procedure before the return, when the remote procedure call (RPC) request has been serviced or when any abnormal condition occurs.

Parameters

Item Description
xprt Identifies the service handle.

Return Values

Examples

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

rpcprog_t prognum;
rpcvers_t progver;

/* create threads to serv multiple client requests */
void * thread_func(void * xprt)
{
    int         result = 3;
   
    if(svc_sendreply((SVCXPRT *) xprt, (xdrproc_t) xdr_int, 
                           (char *) &result) == FALSE)
    svcerr_systemerr(xprt);
            

    /* call to svc_done which frees resources allocated */
    svc_done((SVCXPRT *)xprt);

    pthread_exit(0);
    }

    /* dispatch routine */
    static void  dispatch(struct svc_req * request, SVCXPRT * xprt)
    {
         int  ret;
         pthread_t  tid;

         if((ret = pthread_create(&tid,NULL,thread_func,
                                   (void *)xprt)) != 0)
         {
              fprintf(stderr,"\nError in pthread_create.\n");
              exit(2);
         }
    }

int main()
{
    int num,mode;
           
    prognum = 0x3fffffffL;
    progver = 0x1L;

    svc_unreg(prognum,progver);

    /* register RPC service */
    num = svc_create(dispatch, prognum, progver, "tcp");
    if (num == 0)
    {
         fprintf(stderr, "Error in svc_create.\n");
         exit(EXIT_FAILURE);
    }
           
    /* server in USER-MT mode */

    mode = RPC_SVC_MT_USER;
    if(rpc_control(RPC_SVC_MTMODE_SET,&mode) == FALSE)
    {
         fprintf(stderr,"\nError in rpc_control!\n");
         exit(EXIT_FAILURE);
    }
  
    svc_run();
    exit(1);
}