svc_raw.c revision 95658
174462Salfred/* $NetBSD: svc_raw.c,v 1.14 2000/07/06 03:10:35 christos Exp $ */ 274462Salfred 31901Swollman/* 41901Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 51901Swollman * unrestricted use provided that this legend is included on all tape 61901Swollman * media and as a part of the software program in whole or part. Users 71901Swollman * may copy or modify Sun RPC without charge, but are not authorized 81901Swollman * to license or distribute it to anyone else except as part of a product or 91901Swollman * program developed by the user. 108870Srgrimes * 111901Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 121901Swollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 131901Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 148870Srgrimes * 151901Swollman * Sun RPC is provided with no support and without any obligation on the 161901Swollman * part of Sun Microsystems, Inc. to assist in its use, correction, 171901Swollman * modification or enhancement. 188870Srgrimes * 191901Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 201901Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 211901Swollman * OR ANY PART THEREOF. 228870Srgrimes * 231901Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 241901Swollman * or profits or other special, indirect and consequential damages, even if 251901Swollman * Sun has been advised of the possibility of such damages. 268870Srgrimes * 271901Swollman * Sun Microsystems, Inc. 281901Swollman * 2550 Garcia Avenue 291901Swollman * Mountain View, California 94043 301901Swollman */ 3174462Salfred/* 3274462Salfred * Copyright (c) 1986-1991 by Sun Microsystems Inc. 3374462Salfred */ 341901Swollman 3574462Salfred/* #ident "@(#)svc_raw.c 1.16 94/04/24 SMI" */ 3674462Salfred 3774462Salfred#if defined(SCCSIDS) && !defined(lint) 3874462Salfredstatic char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro"; 391901Swollman#endif 4092990Sobrien#include <sys/cdefs.h> 4192990Sobrien__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_raw.c 95658 2002-04-28 15:18:50Z des $"); 421901Swollman 431901Swollman/* 441901Swollman * svc_raw.c, This a toy for simple testing and timing. 451901Swollman * Interface to create an rpc client and server in the same UNIX process. 461901Swollman * This lets us similate rpc and get rpc (round trip) overhead, without 4785138Salfred * any interference from the kernel. 481901Swollman * 491901Swollman */ 501901Swollman 5175094Siedowse#include "namespace.h" 5274462Salfred#include "reentrant.h" 531901Swollman#include <rpc/rpc.h> 5474462Salfred#include <sys/types.h> 5574462Salfred#include <rpc/raw.h> 5611666Sphk#include <stdlib.h> 5774462Salfred#include "un-namespace.h" 581901Swollman 5974462Salfred#ifndef UDPMSGSIZE 6074462Salfred#define UDPMSGSIZE 8800 6174462Salfred#endif 6274462Salfred 631901Swollman/* 641901Swollman * This is the "network" that we will be moving data over 651901Swollman */ 6674462Salfredstatic struct svc_raw_private { 6774462Salfred char *raw_buf; /* should be shared with the cl handle */ 681901Swollman SVCXPRT server; 691901Swollman XDR xdr_stream; 701901Swollman char verf_body[MAX_AUTH_BYTES]; 7174462Salfred} *svc_raw_private; 721901Swollman 7374462Salfredextern mutex_t svcraw_lock; 741901Swollman 7592905Sobrienstatic enum xprt_stat svc_raw_stat(SVCXPRT *); 7692905Sobrienstatic bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *); 7792905Sobrienstatic bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *); 7895658Sdesstatic bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *); 7995658Sdesstatic bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *); 8092905Sobrienstatic void svc_raw_destroy(SVCXPRT *); 8192905Sobrienstatic void svc_raw_ops(SVCXPRT *); 8292905Sobrienstatic bool_t svc_raw_control(SVCXPRT *, const u_int, void *); 831901Swollman 8474462Salfredchar *__rpc_rawcombuf = NULL; 8574462Salfred 861901SwollmanSVCXPRT * 8774462Salfredsvc_raw_create() 881901Swollman{ 8974462Salfred struct svc_raw_private *srp; 9074462Salfred/* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */ 911901Swollman 9274462Salfred mutex_lock(&svcraw_lock); 9374462Salfred srp = svc_raw_private; 9474462Salfred if (srp == NULL) { 9574462Salfred srp = (struct svc_raw_private *)calloc(1, sizeof (*srp)); 9674462Salfred if (srp == NULL) { 9774462Salfred mutex_unlock(&svcraw_lock); 9874462Salfred return (NULL); 9974462Salfred } 10074462Salfred if (__rpc_rawcombuf == NULL) 10174462Salfred __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char)); 10274462Salfred srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */ 10374462Salfred svc_raw_private = srp; 1041901Swollman } 10574462Salfred srp->server.xp_fd = FD_SETSIZE; 1061901Swollman srp->server.xp_port = 0; 10774462Salfred srp->server.xp_p3 = NULL; 10874462Salfred svc_raw_ops(&srp->server); 1091901Swollman srp->server.xp_verf.oa_base = srp->verf_body; 11074462Salfred xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE); 11174462Salfred xprt_register(&srp->server); 11274462Salfred mutex_unlock(&svcraw_lock); 1131901Swollman return (&srp->server); 1141901Swollman} 1151901Swollman 11674462Salfred/*ARGSUSED*/ 1171901Swollmanstatic enum xprt_stat 11874462Salfredsvc_raw_stat(xprt) 11974462SalfredSVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */ 1201901Swollman{ 1211901Swollman return (XPRT_IDLE); 1221901Swollman} 1231901Swollman 12474462Salfred/*ARGSUSED*/ 1251901Swollmanstatic bool_t 12674462Salfredsvc_raw_recv(xprt, msg) 1271901Swollman SVCXPRT *xprt; 1281901Swollman struct rpc_msg *msg; 1291901Swollman{ 13074462Salfred struct svc_raw_private *srp; 13174462Salfred XDR *xdrs; 1321901Swollman 13374462Salfred mutex_lock(&svcraw_lock); 13474462Salfred srp = svc_raw_private; 13574462Salfred if (srp == NULL) { 13674462Salfred mutex_unlock(&svcraw_lock); 13774462Salfred return (FALSE); 13874462Salfred } 13974462Salfred mutex_unlock(&svcraw_lock); 14074462Salfred 1411901Swollman xdrs = &srp->xdr_stream; 1421901Swollman xdrs->x_op = XDR_DECODE; 14374462Salfred (void) XDR_SETPOS(xdrs, 0); 14474462Salfred if (! xdr_callmsg(xdrs, msg)) { 14574462Salfred return (FALSE); 14674462Salfred } 1471901Swollman return (TRUE); 1481901Swollman} 1491901Swollman 15074462Salfred/*ARGSUSED*/ 1511901Swollmanstatic bool_t 15274462Salfredsvc_raw_reply(xprt, msg) 1531901Swollman SVCXPRT *xprt; 1541901Swollman struct rpc_msg *msg; 1551901Swollman{ 15674462Salfred struct svc_raw_private *srp; 15774462Salfred XDR *xdrs; 1581901Swollman 15974462Salfred mutex_lock(&svcraw_lock); 16074462Salfred srp = svc_raw_private; 16174462Salfred if (srp == NULL) { 16274462Salfred mutex_unlock(&svcraw_lock); 1631901Swollman return (FALSE); 16474462Salfred } 16574462Salfred mutex_unlock(&svcraw_lock); 16674462Salfred 1671901Swollman xdrs = &srp->xdr_stream; 1681901Swollman xdrs->x_op = XDR_ENCODE; 16974462Salfred (void) XDR_SETPOS(xdrs, 0); 17074462Salfred if (! xdr_replymsg(xdrs, msg)) { 17174462Salfred return (FALSE); 17274462Salfred } 17374462Salfred (void) XDR_GETPOS(xdrs); /* called just for overhead */ 1741901Swollman return (TRUE); 1751901Swollman} 1761901Swollman 17774462Salfred/*ARGSUSED*/ 1781901Swollmanstatic bool_t 17974462Salfredsvc_raw_getargs(xprt, xdr_args, args_ptr) 1801901Swollman SVCXPRT *xprt; 1811901Swollman xdrproc_t xdr_args; 18295658Sdes void *args_ptr; 1831901Swollman{ 18474462Salfred struct svc_raw_private *srp; 1851901Swollman 18674462Salfred mutex_lock(&svcraw_lock); 18774462Salfred srp = svc_raw_private; 18874462Salfred if (srp == NULL) { 18974462Salfred mutex_unlock(&svcraw_lock); 1901901Swollman return (FALSE); 19174462Salfred } 19274462Salfred mutex_unlock(&svcraw_lock); 19374462Salfred return (*xdr_args)(&srp->xdr_stream, args_ptr); 1941901Swollman} 1951901Swollman 19674462Salfred/*ARGSUSED*/ 1971901Swollmanstatic bool_t 19874462Salfredsvc_raw_freeargs(xprt, xdr_args, args_ptr) 1991901Swollman SVCXPRT *xprt; 2001901Swollman xdrproc_t xdr_args; 20195658Sdes void *args_ptr; 2028870Srgrimes{ 20374462Salfred struct svc_raw_private *srp; 20474462Salfred XDR *xdrs; 2051901Swollman 20674462Salfred mutex_lock(&svcraw_lock); 20774462Salfred srp = svc_raw_private; 20874462Salfred if (srp == NULL) { 20974462Salfred mutex_unlock(&svcraw_lock); 2101901Swollman return (FALSE); 21174462Salfred } 21274462Salfred mutex_unlock(&svcraw_lock); 21374462Salfred 2141901Swollman xdrs = &srp->xdr_stream; 2151901Swollman xdrs->x_op = XDR_FREE; 21674462Salfred return (*xdr_args)(xdrs, args_ptr); 2178870Srgrimes} 2181901Swollman 21974462Salfred/*ARGSUSED*/ 2201901Swollmanstatic void 22174462Salfredsvc_raw_destroy(xprt) 22274462SalfredSVCXPRT *xprt; 2231901Swollman{ 2241901Swollman} 22574462Salfred 22674462Salfred/*ARGSUSED*/ 22774462Salfredstatic bool_t 22874462Salfredsvc_raw_control(xprt, rq, in) 22974462Salfred SVCXPRT *xprt; 23074462Salfred const u_int rq; 23174462Salfred void *in; 23274462Salfred{ 23374462Salfred return (FALSE); 23474462Salfred} 23574462Salfred 23674462Salfredstatic void 23774462Salfredsvc_raw_ops(xprt) 23874462Salfred SVCXPRT *xprt; 23974462Salfred{ 24074462Salfred static struct xp_ops ops; 24174462Salfred static struct xp_ops2 ops2; 24274462Salfred extern mutex_t ops_lock; 24374462Salfred 24474462Salfred/* VARIABLES PROTECTED BY ops_lock: ops */ 24574462Salfred 24674462Salfred mutex_lock(&ops_lock); 24774462Salfred if (ops.xp_recv == NULL) { 24874462Salfred ops.xp_recv = svc_raw_recv; 24974462Salfred ops.xp_stat = svc_raw_stat; 25074462Salfred ops.xp_getargs = svc_raw_getargs; 25174462Salfred ops.xp_reply = svc_raw_reply; 25274462Salfred ops.xp_freeargs = svc_raw_freeargs; 25374462Salfred ops.xp_destroy = svc_raw_destroy; 25474462Salfred ops2.xp_control = svc_raw_control; 25574462Salfred } 25674462Salfred xprt->xp_ops = &ops; 25774462Salfred xprt->xp_ops2 = &ops2; 25874462Salfred mutex_unlock(&ops_lock); 25974462Salfred} 260