FreeBSD/sys/rpc/svc_generic.c
/*
 * The highest level interface for server creation.
 * It tries for all the nettokens in that particular class of token
 * and returns the number of handles it can create and/or find.
 *
 * It creates a link list of all the handles it could create.
 * If svc_create() is called multiple times, it uses the handle
 * created earlier instead of creating a new handle every time.
 */
The highest level interface for server creation.
It tries for all the nettokens in that particular class of token
and returns the number of handles it can create and/or find.

It creates a link list of all the handles it could create.
If svc_create() is called multiple times, it uses the handle
created earlier instead of creating a new handle every time.
The highest level interface for server creation . It tries for all the nettokens in that particular class of token and returns the number of handles it can create and / or find . It creates a link list of all the handles it could create . If svc_create () is called multiple times it uses the handle created earlier instead of creating a new handle every time .
int
svc_create(
	SVCPOOL *pool,
	void (*dispatch)(struct svc_req *, SVCXPRT *),
	rpcprog_t prognum,		
	rpcvers_t versnum,		
	const char *nettype)		
{
	int g, num = 0;
	SVCGROUP *grp;
	SVCXPRT *xprt;
	struct netconfig *nconf;
	void *handle;
	if ((handle = __rpc_setconf(nettype)) == NULL) {
		printf("svc_create: unknown protocol");
		return (0);
	}
	while ((nconf = __rpc_getconf(handle)) != NULL) {
		for (g = 0; g < SVC_MAXGROUPS; g++) {
			grp = &pool->sp_groups[g];
			mtx_lock(&grp->sg_lock);
			TAILQ_FOREACH(xprt, &grp->sg_xlist, xp_link) {
				if (strcmp(xprt->xp_netid, nconf->nc_netid))
					continue;
				mtx_unlock(&grp->sg_lock);
				(void) rpcb_unset(prognum, versnum, nconf);
				if (svc_reg(xprt, prognum, versnum,
					dispatch, nconf) == FALSE) {
					printf(
		"svc_create: could not register prog %u vers %u on %s\n",
					(unsigned)prognum, (unsigned)versnum,
					 nconf->nc_netid);
					mtx_lock(&grp->sg_lock);
				} else {
					num++;
					mtx_lock(&grp->sg_lock);
					break;
				}
			}
			mtx_unlock(&grp->sg_lock);
		}
		if (xprt == NULL) {
			xprt = svc_tp_create(pool, dispatch, prognum, versnum,
			    NULL, nconf);
			if (xprt) {
				num++;
				SVC_RELEASE(xprt);
			}
		}
	}
	__rpc_endconf(handle);
	return (num);
}
int svc_create ( SVCPOOL * pool , void ( * dispatch ) ( struct svc_req * , SVCXPRT * ) , rpcprog_t prognum , rpcvers_t versnum , const char * nettype ) { int g , num = 0 ; SVCGROUP * grp ; SVCXPRT * xprt ; struct netconfig * nconf ; void * handle ; if ( ( handle = __rpc_setconf ( nettype ) ) == NULL ) { printf ( " " ) ; return ( 0 ) ; } while ( ( nconf = __rpc_getconf ( handle ) ) != NULL ) { for ( g = 0 ; g < SVC_MAXGROUPS ; g ++ ) { grp = & pool -> sp_groups [ g ] ; mtx_lock ( & grp -> sg_lock ) ; TAILQ_FOREACH ( xprt , & grp -> sg_xlist , xp_link ) { if ( strcmp ( xprt -> xp_netid , nconf -> nc_netid ) ) continue ; mtx_unlock ( & grp -> sg_lock ) ; ( void ) rpcb_unset ( prognum , versnum , nconf ) ; if ( svc_reg ( xprt , prognum , versnum , dispatch , nconf ) == FALSE ) { printf ( " \n " , ( unsigned ) prognum , ( unsigned ) versnum , nconf -> nc_netid ) ; mtx_lock ( & grp -> sg_lock ) ; } else { num ++ ; mtx_lock ( & grp -> sg_lock ) ; break ; } } mtx_unlock ( & grp -> sg_lock ) ; } if ( xprt == NULL ) { xprt = svc_tp_create ( pool , dispatch , prognum , versnum , NULL , nconf ) ; if ( xprt ) { num ++ ; SVC_RELEASE ( xprt ) ; } } } __rpc_endconf ( handle ) ; return ( num ) ; }
The highest level interface for server creation.
The highest level interface for server creation .
/* Program number */ /* Version number */ /* Networktype token */ /* Found an old one, use it */ /* It was not found. Now create a new one */ /*
	 * In case of num == 0; the error messages are generated by the
	 * underlying layers; and hence not needed here.
	 */