Home | History | Annotate | Line # | Download | only in rpc
svc_raw.c revision 1.3.4.1
      1 /*	$NetBSD: svc_raw.c,v 1.3.4.1 1996/09/16 23:44:38 jtc Exp $	*/
      2 
      3 /*
      4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5  * unrestricted use provided that this legend is included on all tape
      6  * media and as a part of the software program in whole or part.  Users
      7  * may copy or modify Sun RPC without charge, but are not authorized
      8  * to license or distribute it to anyone else except as part of a product or
      9  * program developed by the user.
     10  *
     11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14  *
     15  * Sun RPC is provided with no support and without any obligation on the
     16  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17  * modification or enhancement.
     18  *
     19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21  * OR ANY PART THEREOF.
     22  *
     23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24  * or profits or other special, indirect and consequential damages, even if
     25  * Sun has been advised of the possibility of such damages.
     26  *
     27  * Sun Microsystems, Inc.
     28  * 2550 Garcia Avenue
     29  * Mountain View, California  94043
     30  */
     31 
     32 #if defined(LIBC_SCCS) && !defined(lint)
     33 /*static char *sccsid = "from: @(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
     34 /*static char *sccsid = "from: @(#)svc_raw.c	2.1 88/07/29 4.0 RPCSRC";*/
     35 static char *rcsid = "$NetBSD: svc_raw.c,v 1.3.4.1 1996/09/16 23:44:38 jtc Exp $";
     36 #endif
     37 
     38 /*
     39  * svc_raw.c,   This a toy for simple testing and timing.
     40  * Interface to create an rpc client and server in the same UNIX process.
     41  * This lets us similate rpc and get rpc (round trip) overhead, without
     42  * any interference from the kernal.
     43  *
     44  * Copyright (C) 1984, Sun Microsystems, Inc.
     45  */
     46 
     47 #include "namespace.h"
     48 #include <stdlib.h>
     49 #include <rpc/rpc.h>
     50 
     51 #ifdef __weak_alias
     52 __weak_alias(svcraw_create,_svcraw_create);
     53 #endif
     54 
     55 
     56 /*
     57  * This is the "network" that we will be moving data over
     58  */
     59 static struct svcraw_private {
     60 	char	_raw_buf[UDPMSGSIZE];
     61 	SVCXPRT	server;
     62 	XDR	xdr_stream;
     63 	char	verf_body[MAX_AUTH_BYTES];
     64 } *svcraw_private;
     65 
     66 static bool_t		svcraw_recv();
     67 static enum xprt_stat 	svcraw_stat();
     68 static bool_t		svcraw_getargs();
     69 static bool_t		svcraw_reply();
     70 static bool_t		svcraw_freeargs();
     71 static void		svcraw_destroy();
     72 
     73 static struct xp_ops server_ops = {
     74 	svcraw_recv,
     75 	svcraw_stat,
     76 	svcraw_getargs,
     77 	svcraw_reply,
     78 	svcraw_freeargs,
     79 	svcraw_destroy
     80 };
     81 
     82 SVCXPRT *
     83 svcraw_create()
     84 {
     85 	register struct svcraw_private *srp = svcraw_private;
     86 
     87 	if (srp == 0) {
     88 		srp = (struct svcraw_private *)calloc(1, sizeof (*srp));
     89 		if (srp == 0)
     90 			return (0);
     91 	}
     92 	srp->server.xp_sock = 0;
     93 	srp->server.xp_port = 0;
     94 	srp->server.xp_ops = &server_ops;
     95 	srp->server.xp_verf.oa_base = srp->verf_body;
     96 	xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
     97 	return (&srp->server);
     98 }
     99 
    100 static enum xprt_stat
    101 svcraw_stat()
    102 {
    103 
    104 	return (XPRT_IDLE);
    105 }
    106 
    107 static bool_t
    108 svcraw_recv(xprt, msg)
    109 	SVCXPRT *xprt;
    110 	struct rpc_msg *msg;
    111 {
    112 	register struct svcraw_private *srp = svcraw_private;
    113 	register XDR *xdrs;
    114 
    115 	if (srp == 0)
    116 		return (0);
    117 	xdrs = &srp->xdr_stream;
    118 	xdrs->x_op = XDR_DECODE;
    119 	XDR_SETPOS(xdrs, 0);
    120 	if (! xdr_callmsg(xdrs, msg))
    121 	       return (FALSE);
    122 	return (TRUE);
    123 }
    124 
    125 static bool_t
    126 svcraw_reply(xprt, msg)
    127 	SVCXPRT *xprt;
    128 	struct rpc_msg *msg;
    129 {
    130 	register struct svcraw_private *srp = svcraw_private;
    131 	register XDR *xdrs;
    132 
    133 	if (srp == 0)
    134 		return (FALSE);
    135 	xdrs = &srp->xdr_stream;
    136 	xdrs->x_op = XDR_ENCODE;
    137 	XDR_SETPOS(xdrs, 0);
    138 	if (! xdr_replymsg(xdrs, msg))
    139 	       return (FALSE);
    140 	(void)XDR_GETPOS(xdrs);  /* called just for overhead */
    141 	return (TRUE);
    142 }
    143 
    144 static bool_t
    145 svcraw_getargs(xprt, xdr_args, args_ptr)
    146 	SVCXPRT *xprt;
    147 	xdrproc_t xdr_args;
    148 	caddr_t args_ptr;
    149 {
    150 	register struct svcraw_private *srp = svcraw_private;
    151 
    152 	if (srp == 0)
    153 		return (FALSE);
    154 	return ((*xdr_args)(&srp->xdr_stream, args_ptr));
    155 }
    156 
    157 static bool_t
    158 svcraw_freeargs(xprt, xdr_args, args_ptr)
    159 	SVCXPRT *xprt;
    160 	xdrproc_t xdr_args;
    161 	caddr_t args_ptr;
    162 {
    163 	register struct svcraw_private *srp = svcraw_private;
    164 	register XDR *xdrs;
    165 
    166 	if (srp == 0)
    167 		return (FALSE);
    168 	xdrs = &srp->xdr_stream;
    169 	xdrs->x_op = XDR_FREE;
    170 	return ((*xdr_args)(xdrs, args_ptr));
    171 }
    172 
    173 static void
    174 svcraw_destroy()
    175 {
    176 }
    177