svc_raw.c revision 1901
11901Swollman/*
21901Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
31901Swollman * unrestricted use provided that this legend is included on all tape
41901Swollman * media and as a part of the software program in whole or part.  Users
51901Swollman * may copy or modify Sun RPC without charge, but are not authorized
61901Swollman * to license or distribute it to anyone else except as part of a product or
71901Swollman * program developed by the user.
81901Swollman *
91901Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
101901Swollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
111901Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
121901Swollman *
131901Swollman * Sun RPC is provided with no support and without any obligation on the
141901Swollman * part of Sun Microsystems, Inc. to assist in its use, correction,
151901Swollman * modification or enhancement.
161901Swollman *
171901Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
181901Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
191901Swollman * OR ANY PART THEREOF.
201901Swollman *
211901Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue
221901Swollman * or profits or other special, indirect and consequential damages, even if
231901Swollman * Sun has been advised of the possibility of such damages.
241901Swollman *
251901Swollman * Sun Microsystems, Inc.
261901Swollman * 2550 Garcia Avenue
271901Swollman * Mountain View, California  94043
281901Swollman */
291901Swollman
301901Swollman#if defined(LIBC_SCCS) && !defined(lint)
311901Swollman/*static char *sccsid = "from: @(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
321901Swollman/*static char *sccsid = "from: @(#)svc_raw.c	2.1 88/07/29 4.0 RPCSRC";*/
331901Swollmanstatic char *rcsid = "$Id: svc_raw.c,v 1.1 1993/10/27 05:40:59 paul Exp $";
341901Swollman#endif
351901Swollman
361901Swollman/*
371901Swollman * svc_raw.c,   This a toy for simple testing and timing.
381901Swollman * Interface to create an rpc client and server in the same UNIX process.
391901Swollman * This lets us similate rpc and get rpc (round trip) overhead, without
401901Swollman * any interference from the kernal.
411901Swollman *
421901Swollman * Copyright (C) 1984, Sun Microsystems, Inc.
431901Swollman */
441901Swollman
451901Swollman#include <rpc/rpc.h>
461901Swollman
471901Swollman
481901Swollman/*
491901Swollman * This is the "network" that we will be moving data over
501901Swollman */
511901Swollmanstatic struct svcraw_private {
521901Swollman	char	_raw_buf[UDPMSGSIZE];
531901Swollman	SVCXPRT	server;
541901Swollman	XDR	xdr_stream;
551901Swollman	char	verf_body[MAX_AUTH_BYTES];
561901Swollman} *svcraw_private;
571901Swollman
581901Swollmanstatic bool_t		svcraw_recv();
591901Swollmanstatic enum xprt_stat 	svcraw_stat();
601901Swollmanstatic bool_t		svcraw_getargs();
611901Swollmanstatic bool_t		svcraw_reply();
621901Swollmanstatic bool_t		svcraw_freeargs();
631901Swollmanstatic void		svcraw_destroy();
641901Swollman
651901Swollmanstatic struct xp_ops server_ops = {
661901Swollman	svcraw_recv,
671901Swollman	svcraw_stat,
681901Swollman	svcraw_getargs,
691901Swollman	svcraw_reply,
701901Swollman	svcraw_freeargs,
711901Swollman	svcraw_destroy
721901Swollman};
731901Swollman
741901SwollmanSVCXPRT *
751901Swollmansvcraw_create()
761901Swollman{
771901Swollman	register struct svcraw_private *srp = svcraw_private;
781901Swollman
791901Swollman	if (srp == 0) {
801901Swollman		srp = (struct svcraw_private *)calloc(1, sizeof (*srp));
811901Swollman		if (srp == 0)
821901Swollman			return (0);
831901Swollman	}
841901Swollman	srp->server.xp_sock = 0;
851901Swollman	srp->server.xp_port = 0;
861901Swollman	srp->server.xp_ops = &server_ops;
871901Swollman	srp->server.xp_verf.oa_base = srp->verf_body;
881901Swollman	xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
891901Swollman	return (&srp->server);
901901Swollman}
911901Swollman
921901Swollmanstatic enum xprt_stat
931901Swollmansvcraw_stat()
941901Swollman{
951901Swollman
961901Swollman	return (XPRT_IDLE);
971901Swollman}
981901Swollman
991901Swollmanstatic bool_t
1001901Swollmansvcraw_recv(xprt, msg)
1011901Swollman	SVCXPRT *xprt;
1021901Swollman	struct rpc_msg *msg;
1031901Swollman{
1041901Swollman	register struct svcraw_private *srp = svcraw_private;
1051901Swollman	register XDR *xdrs;
1061901Swollman
1071901Swollman	if (srp == 0)
1081901Swollman		return (0);
1091901Swollman	xdrs = &srp->xdr_stream;
1101901Swollman	xdrs->x_op = XDR_DECODE;
1111901Swollman	XDR_SETPOS(xdrs, 0);
1121901Swollman	if (! xdr_callmsg(xdrs, msg))
1131901Swollman	       return (FALSE);
1141901Swollman	return (TRUE);
1151901Swollman}
1161901Swollman
1171901Swollmanstatic bool_t
1181901Swollmansvcraw_reply(xprt, msg)
1191901Swollman	SVCXPRT *xprt;
1201901Swollman	struct rpc_msg *msg;
1211901Swollman{
1221901Swollman	register struct svcraw_private *srp = svcraw_private;
1231901Swollman	register XDR *xdrs;
1241901Swollman
1251901Swollman	if (srp == 0)
1261901Swollman		return (FALSE);
1271901Swollman	xdrs = &srp->xdr_stream;
1281901Swollman	xdrs->x_op = XDR_ENCODE;
1291901Swollman	XDR_SETPOS(xdrs, 0);
1301901Swollman	if (! xdr_replymsg(xdrs, msg))
1311901Swollman	       return (FALSE);
1321901Swollman	(void)XDR_GETPOS(xdrs);  /* called just for overhead */
1331901Swollman	return (TRUE);
1341901Swollman}
1351901Swollman
1361901Swollmanstatic bool_t
1371901Swollmansvcraw_getargs(xprt, xdr_args, args_ptr)
1381901Swollman	SVCXPRT *xprt;
1391901Swollman	xdrproc_t xdr_args;
1401901Swollman	caddr_t args_ptr;
1411901Swollman{
1421901Swollman	register struct svcraw_private *srp = svcraw_private;
1431901Swollman
1441901Swollman	if (srp == 0)
1451901Swollman		return (FALSE);
1461901Swollman	return ((*xdr_args)(&srp->xdr_stream, args_ptr));
1471901Swollman}
1481901Swollman
1491901Swollmanstatic bool_t
1501901Swollmansvcraw_freeargs(xprt, xdr_args, args_ptr)
1511901Swollman	SVCXPRT *xprt;
1521901Swollman	xdrproc_t xdr_args;
1531901Swollman	caddr_t args_ptr;
1541901Swollman{
1551901Swollman	register struct svcraw_private *srp = svcraw_private;
1561901Swollman	register XDR *xdrs;
1571901Swollman
1581901Swollman	if (srp == 0)
1591901Swollman		return (FALSE);
1601901Swollman	xdrs = &srp->xdr_stream;
1611901Swollman	xdrs->x_op = XDR_FREE;
1621901Swollman	return ((*xdr_args)(xdrs, args_ptr));
1631901Swollman}
1641901Swollman
1651901Swollmanstatic void
1661901Swollmansvcraw_destroy()
1671901Swollman{
1681901Swollman}
169