1 /* $NetBSD: svc_raw.c,v 1.14 2000/07/06 03:10:35 christos Exp $ */
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.
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.
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.
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.
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.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
35 /* #ident "@(#)svc_raw.c 1.16 94/04/24 SMI" */
37 #if defined(LIBC_SCCS) && !defined(lint)
38 static char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
44 * svc_raw.c, This a toy for simple testing and timing.
45 * Interface to create an rpc client and server in the same UNIX process.
46 * This lets us similate rpc and get rpc (round trip) overhead, without
47 * any interference from the kernel.
51 #include "namespace.h"
52 #include "reentrant.h"
54 #include <sys/types.h>
57 #include "un-namespace.h"
61 #define UDPMSGSIZE 8800
65 * This is the "network" that we will be moving data over
67 static struct svc_raw_private {
68 char *raw_buf; /* should be shared with the cl handle */
71 char verf_body[MAX_AUTH_BYTES];
74 static enum xprt_stat svc_raw_stat(SVCXPRT *);
75 static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *);
76 static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *);
77 static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *);
78 static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *);
79 static void svc_raw_destroy(SVCXPRT *);
80 static void svc_raw_ops(SVCXPRT *);
81 static bool_t svc_raw_control(SVCXPRT *, const u_int, void *);
83 char *__rpc_rawcombuf = NULL;
88 struct svc_raw_private *srp;
89 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
91 mutex_lock(&svcraw_lock);
92 srp = svc_raw_private;
94 srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
96 mutex_unlock(&svcraw_lock);
99 if (__rpc_rawcombuf == NULL) {
100 __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
101 if (__rpc_rawcombuf == NULL) {
103 mutex_unlock(&svcraw_lock);
107 srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
108 srp->server = svc_xprt_alloc();
109 if (srp->server == NULL) {
110 free(__rpc_rawcombuf);
112 mutex_unlock(&svcraw_lock);
115 svc_raw_private = srp;
117 srp->server->xp_fd = FD_SETSIZE;
118 srp->server->xp_port = 0;
119 svc_raw_ops(srp->server);
120 srp->server->xp_verf.oa_base = srp->verf_body;
121 xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE);
122 xprt_register(srp->server);
123 mutex_unlock(&svcraw_lock);
124 return (srp->server);
128 static enum xprt_stat
130 SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */
137 svc_raw_recv(xprt, msg)
141 struct svc_raw_private *srp;
144 mutex_lock(&svcraw_lock);
145 srp = svc_raw_private;
147 mutex_unlock(&svcraw_lock);
150 mutex_unlock(&svcraw_lock);
152 xdrs = &srp->xdr_stream;
153 xdrs->x_op = XDR_DECODE;
154 (void) XDR_SETPOS(xdrs, 0);
155 if (! xdr_callmsg(xdrs, msg)) {
163 svc_raw_reply(xprt, msg)
167 struct svc_raw_private *srp;
173 mutex_lock(&svcraw_lock);
174 srp = svc_raw_private;
176 mutex_unlock(&svcraw_lock);
179 mutex_unlock(&svcraw_lock);
181 xdrs = &srp->xdr_stream;
182 xdrs->x_op = XDR_ENCODE;
183 (void) XDR_SETPOS(xdrs, 0);
184 if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
185 msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
186 xdr_proc = msg->acpted_rply.ar_results.proc;
187 xdr_where = msg->acpted_rply.ar_results.where;
188 msg->acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
189 msg->acpted_rply.ar_results.where = NULL;
191 stat = xdr_replymsg(xdrs, msg) &&
192 SVCAUTH_WRAP(&SVC_AUTH(xprt), xdrs, xdr_proc, xdr_where);
194 stat = xdr_replymsg(xdrs, msg);
199 (void) XDR_GETPOS(xdrs); /* called just for overhead */
205 svc_raw_getargs(xprt, xdr_args, args_ptr)
210 struct svc_raw_private *srp;
212 mutex_lock(&svcraw_lock);
213 srp = svc_raw_private;
215 mutex_unlock(&svcraw_lock);
218 mutex_unlock(&svcraw_lock);
220 return (SVCAUTH_UNWRAP(&SVC_AUTH(xprt), &srp->xdr_stream,
221 xdr_args, args_ptr));
226 svc_raw_freeargs(xprt, xdr_args, args_ptr)
231 struct svc_raw_private *srp;
234 mutex_lock(&svcraw_lock);
235 srp = svc_raw_private;
237 mutex_unlock(&svcraw_lock);
240 mutex_unlock(&svcraw_lock);
242 xdrs = &srp->xdr_stream;
243 xdrs->x_op = XDR_FREE;
244 return (*xdr_args)(xdrs, args_ptr);
249 svc_raw_destroy(xprt)
256 svc_raw_control(xprt, rq, in)
268 static struct xp_ops ops;
269 static struct xp_ops2 ops2;
271 /* VARIABLES PROTECTED BY ops_lock: ops */
273 mutex_lock(&ops_lock);
274 if (ops.xp_recv == NULL) {
275 ops.xp_recv = svc_raw_recv;
276 ops.xp_stat = svc_raw_stat;
277 ops.xp_getargs = svc_raw_getargs;
278 ops.xp_reply = svc_raw_reply;
279 ops.xp_freeargs = svc_raw_freeargs;
280 ops.xp_destroy = svc_raw_destroy;
281 ops2.xp_control = svc_raw_control;
284 xprt->xp_ops2 = &ops2;
285 mutex_unlock(&ops_lock);