Creates a server handle for the specified transport.
Network Services Library (libnsl.a)
#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;
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.
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. |
Item | Description |
---|---|
a service handle | successful |
NULL | unsuccessful |
#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 */
}