svc_raw.c revision 74462
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 0 3874462Salfred#if defined(SCCSIDS) && !defined(lint) 3974462Salfredstatic char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro"; 4050476Speterstatic char *rcsid = "$FreeBSD: head/lib/libc/rpc/svc_raw.c 74462 2001-03-19 12:50:13Z alfred $"; 411901Swollman#endif 4274462Salfred#endif 431901Swollman 441901Swollman/* 451901Swollman * svc_raw.c, This a toy for simple testing and timing. 461901Swollman * Interface to create an rpc client and server in the same UNIX process. 471901Swollman * This lets us similate rpc and get rpc (round trip) overhead, without 481901Swollman * any interference from the kernal. 491901Swollman * 501901Swollman */ 511901Swollman 5274462Salfred#include "reentrant.h" 5374462Salfred#include "namespace.h" 541901Swollman#include <rpc/rpc.h> 5574462Salfred#include <sys/types.h> 5674462Salfred#include <rpc/raw.h> 5711666Sphk#include <stdlib.h> 5874462Salfred#include "un-namespace.h" 591901Swollman 6074462Salfred#ifndef UDPMSGSIZE 6174462Salfred#define UDPMSGSIZE 8800 6274462Salfred#endif 6374462Salfred 641901Swollman/* 651901Swollman * This is the "network" that we will be moving data over 661901Swollman */ 6774462Salfredstatic struct svc_raw_private { 6874462Salfred char *raw_buf; /* should be shared with the cl handle */ 691901Swollman SVCXPRT server; 701901Swollman XDR xdr_stream; 711901Swollman char verf_body[MAX_AUTH_BYTES]; 7274462Salfred} *svc_raw_private; 731901Swollman 7474462Salfredextern mutex_t svcraw_lock; 751901Swollman 7674462Salfredstatic enum xprt_stat svc_raw_stat __P((SVCXPRT *)); 7774462Salfredstatic bool_t svc_raw_recv __P((SVCXPRT *, struct rpc_msg *)); 7874462Salfredstatic bool_t svc_raw_reply __P((SVCXPRT *, struct rpc_msg *)); 7974462Salfredstatic bool_t svc_raw_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 8074462Salfredstatic bool_t svc_raw_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 8174462Salfredstatic void svc_raw_destroy __P((SVCXPRT *)); 8274462Salfredstatic void svc_raw_ops __P((SVCXPRT *)); 8374462Salfredstatic bool_t svc_raw_control __P((SVCXPRT *, const u_int, void *)); 841901Swollman 8574462Salfredchar *__rpc_rawcombuf = NULL; 8674462Salfred 871901SwollmanSVCXPRT * 8874462Salfredsvc_raw_create() 891901Swollman{ 9074462Salfred struct svc_raw_private *srp; 9174462Salfred/* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */ 921901Swollman 9374462Salfred mutex_lock(&svcraw_lock); 9474462Salfred srp = svc_raw_private; 9574462Salfred if (srp == NULL) { 9674462Salfred srp = (struct svc_raw_private *)calloc(1, sizeof (*srp)); 9774462Salfred if (srp == NULL) { 9874462Salfred mutex_unlock(&svcraw_lock); 9974462Salfred return (NULL); 10074462Salfred } 10174462Salfred if (__rpc_rawcombuf == NULL) 10274462Salfred __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char)); 10374462Salfred srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */ 10474462Salfred svc_raw_private = srp; 1051901Swollman } 10674462Salfred srp->server.xp_fd = FD_SETSIZE; 1071901Swollman srp->server.xp_port = 0; 10874462Salfred srp->server.xp_p3 = NULL; 10974462Salfred svc_raw_ops(&srp->server); 1101901Swollman srp->server.xp_verf.oa_base = srp->verf_body; 11174462Salfred xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE); 11274462Salfred xprt_register(&srp->server); 11374462Salfred mutex_unlock(&svcraw_lock); 1141901Swollman return (&srp->server); 1151901Swollman} 1161901Swollman 11774462Salfred/*ARGSUSED*/ 1181901Swollmanstatic enum xprt_stat 11974462Salfredsvc_raw_stat(xprt) 12074462SalfredSVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */ 1211901Swollman{ 1221901Swollman return (XPRT_IDLE); 1231901Swollman} 1241901Swollman 12574462Salfred/*ARGSUSED*/ 1261901Swollmanstatic bool_t 12774462Salfredsvc_raw_recv(xprt, msg) 1281901Swollman SVCXPRT *xprt; 1291901Swollman struct rpc_msg *msg; 1301901Swollman{ 13174462Salfred struct svc_raw_private *srp; 13274462Salfred XDR *xdrs; 1331901Swollman 13474462Salfred mutex_lock(&svcraw_lock); 13574462Salfred srp = svc_raw_private; 13674462Salfred if (srp == NULL) { 13774462Salfred mutex_unlock(&svcraw_lock); 13874462Salfred return (FALSE); 13974462Salfred } 14074462Salfred mutex_unlock(&svcraw_lock); 14174462Salfred 1421901Swollman xdrs = &srp->xdr_stream; 1431901Swollman xdrs->x_op = XDR_DECODE; 14474462Salfred (void) XDR_SETPOS(xdrs, 0); 14574462Salfred if (! xdr_callmsg(xdrs, msg)) { 14674462Salfred return (FALSE); 14774462Salfred } 1481901Swollman return (TRUE); 1491901Swollman} 1501901Swollman 15174462Salfred/*ARGSUSED*/ 1521901Swollmanstatic bool_t 15374462Salfredsvc_raw_reply(xprt, msg) 1541901Swollman SVCXPRT *xprt; 1551901Swollman struct rpc_msg *msg; 1561901Swollman{ 15774462Salfred struct svc_raw_private *srp; 15874462Salfred XDR *xdrs; 1591901Swollman 16074462Salfred mutex_lock(&svcraw_lock); 16174462Salfred srp = svc_raw_private; 16274462Salfred if (srp == NULL) { 16374462Salfred mutex_unlock(&svcraw_lock); 1641901Swollman return (FALSE); 16574462Salfred } 16674462Salfred mutex_unlock(&svcraw_lock); 16774462Salfred 1681901Swollman xdrs = &srp->xdr_stream; 1691901Swollman xdrs->x_op = XDR_ENCODE; 17074462Salfred (void) XDR_SETPOS(xdrs, 0); 17174462Salfred if (! xdr_replymsg(xdrs, msg)) { 17274462Salfred return (FALSE); 17374462Salfred } 17474462Salfred (void) XDR_GETPOS(xdrs); /* called just for overhead */ 1751901Swollman return (TRUE); 1761901Swollman} 1771901Swollman 17874462Salfred/*ARGSUSED*/ 1791901Swollmanstatic bool_t 18074462Salfredsvc_raw_getargs(xprt, xdr_args, args_ptr) 1811901Swollman SVCXPRT *xprt; 1821901Swollman xdrproc_t xdr_args; 1831901Swollman caddr_t args_ptr; 1841901Swollman{ 18574462Salfred struct svc_raw_private *srp; 1861901Swollman 18774462Salfred mutex_lock(&svcraw_lock); 18874462Salfred srp = svc_raw_private; 18974462Salfred if (srp == NULL) { 19074462Salfred mutex_unlock(&svcraw_lock); 1911901Swollman return (FALSE); 19274462Salfred } 19374462Salfred mutex_unlock(&svcraw_lock); 19474462Salfred return (*xdr_args)(&srp->xdr_stream, args_ptr); 1951901Swollman} 1961901Swollman 19774462Salfred/*ARGSUSED*/ 1981901Swollmanstatic bool_t 19974462Salfredsvc_raw_freeargs(xprt, xdr_args, args_ptr) 2001901Swollman SVCXPRT *xprt; 2011901Swollman xdrproc_t xdr_args; 2021901Swollman caddr_t args_ptr; 2038870Srgrimes{ 20474462Salfred struct svc_raw_private *srp; 20574462Salfred XDR *xdrs; 2061901Swollman 20774462Salfred mutex_lock(&svcraw_lock); 20874462Salfred srp = svc_raw_private; 20974462Salfred if (srp == NULL) { 21074462Salfred mutex_unlock(&svcraw_lock); 2111901Swollman return (FALSE); 21274462Salfred } 21374462Salfred mutex_unlock(&svcraw_lock); 21474462Salfred 2151901Swollman xdrs = &srp->xdr_stream; 2161901Swollman xdrs->x_op = XDR_FREE; 21774462Salfred return (*xdr_args)(xdrs, args_ptr); 2188870Srgrimes} 2191901Swollman 22074462Salfred/*ARGSUSED*/ 2211901Swollmanstatic void 22274462Salfredsvc_raw_destroy(xprt) 22374462SalfredSVCXPRT *xprt; 2241901Swollman{ 2251901Swollman} 22674462Salfred 22774462Salfred/*ARGSUSED*/ 22874462Salfredstatic bool_t 22974462Salfredsvc_raw_control(xprt, rq, in) 23074462Salfred SVCXPRT *xprt; 23174462Salfred const u_int rq; 23274462Salfred void *in; 23374462Salfred{ 23474462Salfred return (FALSE); 23574462Salfred} 23674462Salfred 23774462Salfredstatic void 23874462Salfredsvc_raw_ops(xprt) 23974462Salfred SVCXPRT *xprt; 24074462Salfred{ 24174462Salfred static struct xp_ops ops; 24274462Salfred static struct xp_ops2 ops2; 24374462Salfred extern mutex_t ops_lock; 24474462Salfred 24574462Salfred/* VARIABLES PROTECTED BY ops_lock: ops */ 24674462Salfred 24774462Salfred mutex_lock(&ops_lock); 24874462Salfred if (ops.xp_recv == NULL) { 24974462Salfred ops.xp_recv = svc_raw_recv; 25074462Salfred ops.xp_stat = svc_raw_stat; 25174462Salfred ops.xp_getargs = svc_raw_getargs; 25274462Salfred ops.xp_reply = svc_raw_reply; 25374462Salfred ops.xp_freeargs = svc_raw_freeargs; 25474462Salfred ops.xp_destroy = svc_raw_destroy; 25574462Salfred ops2.xp_control = svc_raw_control; 25674462Salfred } 25774462Salfred xprt->xp_ops = &ops; 25874462Salfred xprt->xp_ops2 = &ops2; 25974462Salfred mutex_unlock(&ops_lock); 26074462Salfred} 261