2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * @(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro
29 * @(#)svc_raw.c 1.16 94/04/24 SMI
30 * $NetBSD: svc_raw.c,v 1.14 2000/07/06 03:10:35 christos Exp $
31 * $FreeBSD: src/lib/libc/rpc/svc_raw.c,v 1.15 2006/02/27 22:10:59 deischen Exp $
34 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
38 * svc_raw.c, This a toy for simple testing and timing.
39 * Interface to create an rpc client and server in the same UNIX process.
40 * This lets us similate rpc and get rpc (round trip) overhead, without
41 * any interference from the kernel.
45 #include "namespace.h"
46 #include "reentrant.h"
48 #include <sys/types.h>
51 #include "un-namespace.h"
55 #define UDPMSGSIZE 8800
59 * This is the "network" that we will be moving data over
61 static struct svc_raw_private {
62 char *raw_buf; /* should be shared with the cl handle */
65 char verf_body[MAX_AUTH_BYTES];
68 static enum xprt_stat svc_raw_stat(SVCXPRT *);
69 static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *);
70 static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *);
71 static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *);
72 static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *);
73 static void svc_raw_destroy(SVCXPRT *);
74 static void svc_raw_ops(SVCXPRT *);
75 static bool_t svc_raw_control(SVCXPRT *, const u_int, void *);
77 char *__rpc_rawcombuf = NULL;
82 struct svc_raw_private *srp;
83 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
85 mutex_lock(&svcraw_lock);
86 srp = svc_raw_private;
88 srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
90 mutex_unlock(&svcraw_lock);
93 if (__rpc_rawcombuf == NULL)
94 __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
95 srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
96 svc_raw_private = srp;
98 srp->server.xp_fd = FD_SETSIZE;
99 srp->server.xp_port = 0;
100 srp->server.xp_p3 = NULL;
101 svc_raw_ops(&srp->server);
102 srp->server.xp_verf.oa_base = srp->verf_body;
103 xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE);
104 xprt_register(&srp->server);
105 mutex_unlock(&svcraw_lock);
106 return (&srp->server);
110 static enum xprt_stat
111 svc_raw_stat(SVCXPRT *xprt __unused)
118 svc_raw_recv(SVCXPRT *xprt __unused, struct rpc_msg *msg)
120 struct svc_raw_private *srp;
123 mutex_lock(&svcraw_lock);
124 srp = svc_raw_private;
126 mutex_unlock(&svcraw_lock);
129 mutex_unlock(&svcraw_lock);
131 xdrs = &srp->xdr_stream;
132 xdrs->x_op = XDR_DECODE;
134 if (! xdr_callmsg(xdrs, msg)) {
142 svc_raw_reply(SVCXPRT *xprt __unused, struct rpc_msg *msg)
144 struct svc_raw_private *srp;
147 mutex_lock(&svcraw_lock);
148 srp = svc_raw_private;
150 mutex_unlock(&svcraw_lock);
153 mutex_unlock(&svcraw_lock);
155 xdrs = &srp->xdr_stream;
156 xdrs->x_op = XDR_ENCODE;
158 if (! xdr_replymsg(xdrs, msg)) {
161 XDR_GETPOS(xdrs); /* called just for overhead */
167 svc_raw_getargs(SVCXPRT *xprt __unused, xdrproc_t xdr_args, void *args_ptr)
169 struct svc_raw_private *srp;
171 mutex_lock(&svcraw_lock);
172 srp = svc_raw_private;
174 mutex_unlock(&svcraw_lock);
177 mutex_unlock(&svcraw_lock);
178 return (*xdr_args)(&srp->xdr_stream, args_ptr);
183 svc_raw_freeargs(SVCXPRT *xprt __unused, xdrproc_t xdr_args, void *args_ptr)
185 struct svc_raw_private *srp;
188 mutex_lock(&svcraw_lock);
189 srp = svc_raw_private;
191 mutex_unlock(&svcraw_lock);
194 mutex_unlock(&svcraw_lock);
196 xdrs = &srp->xdr_stream;
197 xdrs->x_op = XDR_FREE;
198 return (*xdr_args)(xdrs, args_ptr);
203 svc_raw_destroy(SVCXPRT *xprt __unused)
209 svc_raw_control(SVCXPRT *xprt __unused, const u_int rq __unused,
216 svc_raw_ops(SVCXPRT *xprt)
218 static struct xp_ops ops;
219 static struct xp_ops2 ops2;
221 /* VARIABLES PROTECTED BY ops_lock: ops */
223 mutex_lock(&ops_lock);
224 if (ops.xp_recv == NULL) {
225 ops.xp_recv = svc_raw_recv;
226 ops.xp_stat = svc_raw_stat;
227 ops.xp_getargs = svc_raw_getargs;
228 ops.xp_reply = svc_raw_reply;
229 ops.xp_freeargs = svc_raw_freeargs;
230 ops.xp_destroy = svc_raw_destroy;
231 ops2.xp_control = svc_raw_control;
234 xprt->xp_ops2 = &ops2;
235 mutex_unlock(&ops_lock);