This code example illustrates an expert-level service API that is used in developing TI-RPC services.
The expert level allows the programmer to specify Send and Receive buffer sizes for services. Calling svc_tli_create() creates the service handle, but it does not register or bind it with the rpcbind daemon. The programmer must call svc_reg() before the service works properly. Similar to the intermediate level, you have the option to use the network selection APIs to retrieve the transport information for the service.
#include <stdio.h> #include <netconfig.h> #include <rpc/rpc.h> #include <errno.h> #include "myapp.h" int main(int argc, char *argv[]) { struct netconfig *nconf; /* pointer to nettype data */ SVCXPRT *svc; /* pointer to service handle */ bool_t rslt; /* return value for svc_reg() */ /* unregister any existing copy of this service */ /* (void)svc_unreg(program, version) */ svc_unreg(PROGNUM, VERSNUM); /* (struct netconfig *)getnetconfigent(nettype) */ nconf = getnetconfigent(NETTYPE); /* check for errors calling getnetconfigent() */ if (nconf == (struct netconfig *)NULL) { /* print error messages and exit */ fprintf(stderr, "Error calling getnetconfigent(%s)\n", NETTYPE); fprintf(stderr, "errno: %d\n", errno); return 1; } /* (SVCXPRT *)svc_tli_create(filedes, netconfig, bindaddr, sendsz, recvsz) */ svc = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0); /* check for errors calling svc_tli_create() */ if (svc == (SVCXPRT *)NULL) { /* print error messages and exit */ fprintf(stderr, "Error calling %s.\n", "svc_tli_create"); fprintf(stderr, "errno: %d\n", errno); return 1; } /* (bool_t)svc_reg(svcxprt, prognum, versnum, dispatch, netconf) */ rslt = svc_reg(svc, PROGNUM, VERSNUM, myapp_dispatch, nconf); /* check for errors calling svc_reg() */ if (rslt == FALSE) { /* print error messages and exit */ fprintf(stderr, "Error calling svc_reg\n"); fprintf(stderr, "PROG: %lu\nVERS: %lu\tNET: %s\n", PROGNUM, VERSNUM, NETTYPE); fprintf(stderr, "errno: %d\n", errno); return 1; } /* this should loop indefinitely waiting for client connections */ svc_run(); /* if we get here, svc_run() returned */ fprintf(stderr, "svc_run() returned. ERROR has occurred.\n"); fprintf(stderr, "errno: %d\n", errno); /* clean up by unregistering. then, exit */ svc_unreg(PROGNUM, VERSNUM); return 1; } /* end of main() */