Home | History | Annotate | Line # | Download | only in rpc
svc_raw.c revision 1.12.2.1
      1  1.12.2.1   minoura /*	$NetBSD: svc_raw.c,v 1.12.2.1 2000/06/23 16:17:52 minoura Exp $	*/
      2       1.3       cgd 
      3       1.1       cgd /*
      4       1.1       cgd  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5       1.1       cgd  * unrestricted use provided that this legend is included on all tape
      6       1.1       cgd  * media and as a part of the software program in whole or part.  Users
      7       1.1       cgd  * may copy or modify Sun RPC without charge, but are not authorized
      8       1.1       cgd  * to license or distribute it to anyone else except as part of a product or
      9       1.1       cgd  * program developed by the user.
     10       1.1       cgd  *
     11       1.1       cgd  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12       1.1       cgd  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13       1.1       cgd  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14       1.1       cgd  *
     15       1.1       cgd  * Sun RPC is provided with no support and without any obligation on the
     16       1.1       cgd  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17       1.1       cgd  * modification or enhancement.
     18       1.1       cgd  *
     19       1.1       cgd  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20       1.1       cgd  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21       1.1       cgd  * OR ANY PART THEREOF.
     22       1.1       cgd  *
     23       1.1       cgd  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24       1.1       cgd  * or profits or other special, indirect and consequential damages, even if
     25       1.1       cgd  * Sun has been advised of the possibility of such damages.
     26       1.1       cgd  *
     27       1.1       cgd  * Sun Microsystems, Inc.
     28       1.1       cgd  * 2550 Garcia Avenue
     29       1.1       cgd  * Mountain View, California  94043
     30       1.1       cgd  */
     31  1.12.2.1   minoura /*
     32  1.12.2.1   minoura  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
     33  1.12.2.1   minoura  */
     34  1.12.2.1   minoura 
     35  1.12.2.1   minoura /* #ident	"@(#)svc_raw.c	1.16	94/04/24 SMI" */
     36       1.1       cgd 
     37       1.4  christos #if 0
     38  1.12.2.1   minoura #if !defined(lint) && defined(SCCSIDS)
     39  1.12.2.1   minoura static char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
     40       1.4  christos #endif
     41       1.1       cgd #endif
     42       1.1       cgd 
     43       1.1       cgd /*
     44       1.1       cgd  * svc_raw.c,   This a toy for simple testing and timing.
     45       1.1       cgd  * Interface to create an rpc client and server in the same UNIX process.
     46       1.1       cgd  * This lets us similate rpc and get rpc (round trip) overhead, without
     47       1.1       cgd  * any interference from the kernal.
     48       1.1       cgd  *
     49       1.1       cgd  */
     50       1.1       cgd 
     51       1.5       jtc #include "namespace.h"
     52  1.12.2.1   minoura #include "reentrant.h"
     53       1.1       cgd #include <rpc/rpc.h>
     54  1.12.2.1   minoura #include <sys/types.h>
     55  1.12.2.1   minoura #include <rpc/raw.h>
     56  1.12.2.1   minoura #include <stdlib.h>
     57       1.1       cgd 
     58       1.5       jtc #ifdef __weak_alias
     59  1.12.2.1   minoura __weak_alias(svc_raw_create,_svc_raw_create)
     60  1.12.2.1   minoura #endif
     61  1.12.2.1   minoura 
     62  1.12.2.1   minoura #ifndef UDPMSGSIZE
     63  1.12.2.1   minoura #define	UDPMSGSIZE 8800
     64       1.5       jtc #endif
     65       1.1       cgd 
     66       1.1       cgd /*
     67       1.1       cgd  * This is the "network" that we will be moving data over
     68       1.1       cgd  */
     69  1.12.2.1   minoura static struct svc_raw_private {
     70  1.12.2.1   minoura 	char	*raw_buf;	/* should be shared with the cl handle */
     71       1.1       cgd 	SVCXPRT	server;
     72       1.1       cgd 	XDR	xdr_stream;
     73       1.1       cgd 	char	verf_body[MAX_AUTH_BYTES];
     74  1.12.2.1   minoura } *svc_raw_private;
     75  1.12.2.1   minoura 
     76  1.12.2.1   minoura #ifdef __REENT
     77  1.12.2.1   minoura extern mutex_t	svcraw_lock;
     78  1.12.2.1   minoura #endif
     79       1.1       cgd 
     80  1.12.2.1   minoura static enum xprt_stat svc_raw_stat __P((SVCXPRT *));
     81  1.12.2.1   minoura static bool_t svc_raw_recv __P((SVCXPRT *, struct rpc_msg *));
     82  1.12.2.1   minoura static bool_t svc_raw_reply __P((SVCXPRT *, struct rpc_msg *));
     83  1.12.2.1   minoura static bool_t svc_raw_getargs __P((SVCXPRT *, xdrproc_t, caddr_t));
     84  1.12.2.1   minoura static bool_t svc_raw_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t));
     85  1.12.2.1   minoura static void svc_raw_destroy __P((SVCXPRT *));
     86  1.12.2.1   minoura static void svc_raw_ops __P((SVCXPRT *));
     87  1.12.2.1   minoura static bool_t svc_raw_control __P((SVCXPRT *, const u_int, void *));
     88  1.12.2.1   minoura 
     89  1.12.2.1   minoura char *__rpc_rawcombuf = NULL;
     90       1.1       cgd 
     91       1.1       cgd SVCXPRT *
     92  1.12.2.1   minoura svc_raw_create()
     93       1.1       cgd {
     94  1.12.2.1   minoura 	struct svc_raw_private *srp;
     95  1.12.2.1   minoura /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
     96       1.1       cgd 
     97  1.12.2.1   minoura 	mutex_lock(&svcraw_lock);
     98  1.12.2.1   minoura 	srp = svc_raw_private;
     99  1.12.2.1   minoura 	if (srp == NULL) {
    100  1.12.2.1   minoura 		srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
    101  1.12.2.1   minoura 		if (srp == NULL) {
    102  1.12.2.1   minoura 			mutex_unlock(&svcraw_lock);
    103  1.12.2.1   minoura 			return ((SVCXPRT *)NULL);
    104  1.12.2.1   minoura 		}
    105  1.12.2.1   minoura 		if (__rpc_rawcombuf == NULL)
    106  1.12.2.1   minoura 			__rpc_rawcombuf =
    107  1.12.2.1   minoura 			    (char *)calloc(UDPMSGSIZE, sizeof (char));
    108  1.12.2.1   minoura 		srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
    109  1.12.2.1   minoura 		svc_raw_private = srp;
    110       1.1       cgd 	}
    111  1.12.2.1   minoura 	srp->server.xp_fd = FD_SETSIZE;
    112       1.1       cgd 	srp->server.xp_port = 0;
    113  1.12.2.1   minoura 	srp->server.xp_p3 = NULL;
    114  1.12.2.1   minoura 	svc_raw_ops(&srp->server);
    115       1.1       cgd 	srp->server.xp_verf.oa_base = srp->verf_body;
    116  1.12.2.1   minoura 	xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE);
    117  1.12.2.1   minoura 	xprt_register(&srp->server);
    118  1.12.2.1   minoura 	mutex_unlock(&svcraw_lock);
    119       1.1       cgd 	return (&srp->server);
    120       1.1       cgd }
    121       1.1       cgd 
    122       1.1       cgd static enum xprt_stat
    123  1.12.2.1   minoura svc_raw_stat(xprt)
    124  1.12.2.1   minoura SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */
    125       1.1       cgd {
    126       1.1       cgd 	return (XPRT_IDLE);
    127       1.1       cgd }
    128       1.1       cgd 
    129       1.1       cgd static bool_t
    130  1.12.2.1   minoura svc_raw_recv(xprt, msg)
    131       1.1       cgd 	SVCXPRT *xprt;
    132       1.1       cgd 	struct rpc_msg *msg;
    133       1.1       cgd {
    134  1.12.2.1   minoura 	struct svc_raw_private *srp;
    135       1.8     lukem 	XDR *xdrs;
    136       1.1       cgd 
    137  1.12.2.1   minoura 	mutex_lock(&svcraw_lock);
    138  1.12.2.1   minoura 	srp = svc_raw_private;
    139  1.12.2.1   minoura 	if (srp == NULL) {
    140  1.12.2.1   minoura 		mutex_unlock(&svcraw_lock);
    141  1.12.2.1   minoura 		return (FALSE);
    142  1.12.2.1   minoura 	}
    143  1.12.2.1   minoura 	mutex_unlock(&svcraw_lock);
    144      1.11     lukem 
    145       1.1       cgd 	xdrs = &srp->xdr_stream;
    146       1.1       cgd 	xdrs->x_op = XDR_DECODE;
    147  1.12.2.1   minoura 	(void) XDR_SETPOS(xdrs, 0);
    148  1.12.2.1   minoura 	if (! xdr_callmsg(xdrs, msg)) {
    149  1.12.2.1   minoura 		return (FALSE);
    150  1.12.2.1   minoura 	}
    151       1.1       cgd 	return (TRUE);
    152       1.1       cgd }
    153       1.1       cgd 
    154       1.1       cgd static bool_t
    155  1.12.2.1   minoura svc_raw_reply(xprt, msg)
    156       1.1       cgd 	SVCXPRT *xprt;
    157       1.1       cgd 	struct rpc_msg *msg;
    158       1.1       cgd {
    159  1.12.2.1   minoura 	struct svc_raw_private *srp;
    160       1.8     lukem 	XDR *xdrs;
    161       1.1       cgd 
    162  1.12.2.1   minoura 	mutex_lock(&svcraw_lock);
    163  1.12.2.1   minoura 	srp = svc_raw_private;
    164  1.12.2.1   minoura 	if (srp == NULL) {
    165  1.12.2.1   minoura 		mutex_unlock(&svcraw_lock);
    166       1.1       cgd 		return (FALSE);
    167  1.12.2.1   minoura 	}
    168  1.12.2.1   minoura 	mutex_unlock(&svcraw_lock);
    169  1.12.2.1   minoura 
    170       1.1       cgd 	xdrs = &srp->xdr_stream;
    171       1.1       cgd 	xdrs->x_op = XDR_ENCODE;
    172  1.12.2.1   minoura 	(void) XDR_SETPOS(xdrs, 0);
    173  1.12.2.1   minoura 	if (! xdr_replymsg(xdrs, msg)) {
    174  1.12.2.1   minoura 		return (FALSE);
    175  1.12.2.1   minoura 	}
    176  1.12.2.1   minoura 	(void) XDR_GETPOS(xdrs);  /* called just for overhead */
    177       1.1       cgd 	return (TRUE);
    178       1.1       cgd }
    179       1.1       cgd 
    180       1.1       cgd static bool_t
    181  1.12.2.1   minoura svc_raw_getargs(xprt, xdr_args, args_ptr)
    182       1.1       cgd 	SVCXPRT *xprt;
    183       1.1       cgd 	xdrproc_t xdr_args;
    184       1.1       cgd 	caddr_t args_ptr;
    185       1.1       cgd {
    186  1.12.2.1   minoura 	register struct svc_raw_private *srp;
    187      1.11     lukem 
    188  1.12.2.1   minoura 	mutex_lock(&svcraw_lock);
    189  1.12.2.1   minoura 	srp = svc_raw_private;
    190  1.12.2.1   minoura 	if (srp == NULL) {
    191  1.12.2.1   minoura 		mutex_unlock(&svcraw_lock);
    192       1.1       cgd 		return (FALSE);
    193  1.12.2.1   minoura 	}
    194  1.12.2.1   minoura 	mutex_unlock(&svcraw_lock);
    195  1.12.2.1   minoura 	return (*xdr_args)(&srp->xdr_stream, args_ptr);
    196       1.1       cgd }
    197       1.1       cgd 
    198       1.1       cgd static bool_t
    199  1.12.2.1   minoura svc_raw_freeargs(xprt, xdr_args, args_ptr)
    200       1.1       cgd 	SVCXPRT *xprt;
    201       1.1       cgd 	xdrproc_t xdr_args;
    202       1.1       cgd 	caddr_t args_ptr;
    203  1.12.2.1   minoura {
    204  1.12.2.1   minoura 	struct svc_raw_private *srp;
    205       1.8     lukem 	XDR *xdrs;
    206      1.11     lukem 
    207  1.12.2.1   minoura 	mutex_lock(&svcraw_lock);
    208  1.12.2.1   minoura 	srp = svc_raw_private;
    209  1.12.2.1   minoura 	if (srp == NULL) {
    210  1.12.2.1   minoura 		mutex_unlock(&svcraw_lock);
    211       1.1       cgd 		return (FALSE);
    212  1.12.2.1   minoura 	}
    213  1.12.2.1   minoura 	mutex_unlock(&svcraw_lock);
    214  1.12.2.1   minoura 
    215       1.1       cgd 	xdrs = &srp->xdr_stream;
    216       1.1       cgd 	xdrs->x_op = XDR_FREE;
    217  1.12.2.1   minoura 	return (*xdr_args)(xdrs, args_ptr);
    218  1.12.2.1   minoura }
    219       1.1       cgd 
    220       1.1       cgd static void
    221  1.12.2.1   minoura svc_raw_destroy(xprt)
    222  1.12.2.1   minoura SVCXPRT *xprt;
    223  1.12.2.1   minoura {
    224  1.12.2.1   minoura }
    225  1.12.2.1   minoura 
    226  1.12.2.1   minoura static bool_t
    227  1.12.2.1   minoura svc_raw_control(xprt, rq, in)
    228  1.12.2.1   minoura 	SVCXPRT *xprt;
    229  1.12.2.1   minoura 	const u_int	rq;
    230  1.12.2.1   minoura 	void		*in;
    231  1.12.2.1   minoura {
    232  1.12.2.1   minoura 	return (FALSE);
    233  1.12.2.1   minoura }
    234  1.12.2.1   minoura 
    235  1.12.2.1   minoura static void
    236  1.12.2.1   minoura svc_raw_ops(xprt)
    237       1.4  christos 	SVCXPRT *xprt;
    238       1.1       cgd {
    239  1.12.2.1   minoura 	static struct xp_ops ops;
    240  1.12.2.1   minoura 	static struct xp_ops2 ops2;
    241  1.12.2.1   minoura #ifdef __REENT
    242  1.12.2.1   minoura 	extern mutex_t ops_lock;
    243  1.12.2.1   minoura #endif
    244  1.12.2.1   minoura 
    245  1.12.2.1   minoura /* VARIABLES PROTECTED BY ops_lock: ops */
    246  1.12.2.1   minoura 
    247  1.12.2.1   minoura 	mutex_lock(&ops_lock);
    248  1.12.2.1   minoura 	if (ops.xp_recv == NULL) {
    249  1.12.2.1   minoura 		ops.xp_recv = svc_raw_recv;
    250  1.12.2.1   minoura 		ops.xp_stat = svc_raw_stat;
    251  1.12.2.1   minoura 		ops.xp_getargs = svc_raw_getargs;
    252  1.12.2.1   minoura 		ops.xp_reply = svc_raw_reply;
    253  1.12.2.1   minoura 		ops.xp_freeargs = svc_raw_freeargs;
    254  1.12.2.1   minoura 		ops.xp_destroy = svc_raw_destroy;
    255  1.12.2.1   minoura 		ops2.xp_control = svc_raw_control;
    256  1.12.2.1   minoura 	}
    257  1.12.2.1   minoura 	xprt->xp_ops = &ops;
    258  1.12.2.1   minoura 	xprt->xp_ops2 = &ops2;
    259  1.12.2.1   minoura 	mutex_unlock(&ops_lock);
    260       1.1       cgd }
    261