1 /* $NetBSD: svc_raw.c,v 1.24 2013/03/11 20:19:29 tron Exp $ */
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
37 /* #ident "@(#)svc_raw.c 1.16 94/04/24 SMI" */
39 #include <sys/cdefs.h>
40 #if defined(LIBC_SCCS) && !defined(lint)
42 static char sccsid
[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
44 __RCSID("$NetBSD: svc_raw.c,v 1.24 2013/03/11 20:19:29 tron Exp $");
49 * svc_raw.c, This a toy for simple testing and timing.
50 * Interface to create an rpc client and server in the same UNIX process.
51 * This lets us similate rpc and get rpc (round trip) overhead, without
52 * any interference from the kernel.
56 #include "namespace.h"
57 #include "reentrant.h"
59 #include <sys/types.h>
65 __weak_alias(svc_raw_create
,_svc_raw_create
)
69 #define UDPMSGSIZE 8800
73 * This is the "network" that we will be moving data over
75 static struct svc_raw_private
{
76 char *raw_buf
; /* should be shared with the cl handle */
79 char verf_body
[MAX_AUTH_BYTES
];
83 extern mutex_t svcraw_lock
;
86 static enum xprt_stat
svc_raw_stat(SVCXPRT
*);
87 static bool_t
svc_raw_recv(SVCXPRT
*, struct rpc_msg
*);
88 static bool_t
svc_raw_reply(SVCXPRT
*, struct rpc_msg
*);
89 static bool_t
svc_raw_getargs(SVCXPRT
*, xdrproc_t
, caddr_t
);
90 static bool_t
svc_raw_freeargs(SVCXPRT
*, xdrproc_t
, caddr_t
);
91 static void svc_raw_destroy(SVCXPRT
*);
92 static void svc_raw_ops(SVCXPRT
*);
93 static bool_t
svc_raw_control(SVCXPRT
*, const u_int
, void *);
95 char *__rpc_rawcombuf
= NULL
;
100 struct svc_raw_private
*srp
;
101 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
103 mutex_lock(&svcraw_lock
);
104 srp
= svc_raw_private
;
106 srp
= calloc(1, sizeof(*srp
));
109 if (__rpc_rawcombuf
== NULL
)
110 __rpc_rawcombuf
= malloc(UDPMSGSIZE
);
111 if (__rpc_rawcombuf
== NULL
)
113 srp
->raw_buf
= __rpc_rawcombuf
; /* Share it with the client */
114 svc_raw_private
= srp
;
116 srp
->server
.xp_fd
= FD_SETSIZE
;
117 srp
->server
.xp_port
= 0;
118 srp
->server
.xp_p3
= NULL
;
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 if (!xprt_register(&srp
->server
))
124 mutex_unlock(&svcraw_lock
);
125 return (&srp
->server
);
129 mutex_unlock(&svcraw_lock
);
134 static enum xprt_stat
135 svc_raw_stat(SVCXPRT
*xprt
) /* args needed to satisfy ANSI-C typechecking */
142 svc_raw_recv(SVCXPRT
*xprt
, 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_DECODE
;
157 (void) XDR_SETPOS(xdrs
, 0);
158 if (! xdr_callmsg(xdrs
, msg
)) {
166 svc_raw_reply(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
168 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
);
179 xdrs
= &srp
->xdr_stream
;
180 xdrs
->x_op
= XDR_ENCODE
;
181 (void) XDR_SETPOS(xdrs
, 0);
182 if (! xdr_replymsg(xdrs
, msg
)) {
185 (void) XDR_GETPOS(xdrs
); /* called just for overhead */
191 svc_raw_getargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
193 struct svc_raw_private
*srp
;
195 mutex_lock(&svcraw_lock
);
196 srp
= svc_raw_private
;
198 mutex_unlock(&svcraw_lock
);
201 mutex_unlock(&svcraw_lock
);
202 return (*xdr_args
)(&srp
->xdr_stream
, args_ptr
);
207 svc_raw_freeargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
209 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 xdrs
= &srp
->xdr_stream
;
221 xdrs
->x_op
= XDR_FREE
;
222 return (*xdr_args
)(xdrs
, args_ptr
);
227 svc_raw_destroy(SVCXPRT
*xprt
)
233 svc_raw_control(SVCXPRT
*xprt
, const u_int rq
, void *in
)
239 svc_raw_ops(SVCXPRT
*xprt
)
241 static struct xp_ops ops
;
242 static struct xp_ops2 ops2
;
244 extern mutex_t ops_lock
;
247 _DIAGASSERT(xprt
!= NULL
);
249 /* VARIABLES PROTECTED BY ops_lock: ops */
251 mutex_lock(&ops_lock
);
252 if (ops
.xp_recv
== NULL
) {
253 ops
.xp_recv
= svc_raw_recv
;
254 ops
.xp_stat
= svc_raw_stat
;
255 ops
.xp_getargs
= svc_raw_getargs
;
256 ops
.xp_reply
= svc_raw_reply
;
257 ops
.xp_freeargs
= svc_raw_freeargs
;
258 ops
.xp_destroy
= svc_raw_destroy
;
259 ops2
.xp_control
= svc_raw_control
;
262 xprt
->xp_ops2
= &ops2
;
263 mutex_unlock(&ops_lock
);