3 * Copyright (c) 2009, Sun Microsystems, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * - Neither the name of Sun Microsystems, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
34 * svc_raw.c, This a toy for simple testing and timing.
35 * Interface to create an rpc client and server in the same UNIX process.
36 * This lets us similate rpc and get rpc (round trip) overhead, without
37 * any interference from the kernel.
41 //#include <pthread.h>
42 #include <reentrant.h>
44 #include <sys/types.h>
49 #define UDPMSGSIZE 8800
53 * This is the "network" that we will be moving data over
55 static struct svc_raw_private
{
56 char *raw_buf
; /* should be shared with the cl handle */
59 char verf_body
[MAX_AUTH_BYTES
];
62 extern mutex_t svcraw_lock
;
64 static enum xprt_stat
svc_raw_stat(SVCXPRT
*);
65 static bool_t
svc_raw_recv(SVCXPRT
*, struct rpc_msg
*);
66 static bool_t
svc_raw_reply(SVCXPRT
*, struct rpc_msg
*);
67 static bool_t
svc_raw_getargs(SVCXPRT
*, xdrproc_t
, void *);
68 static bool_t
svc_raw_freeargs(SVCXPRT
*, xdrproc_t
, void *);
69 static void svc_raw_destroy(SVCXPRT
*);
70 static void svc_raw_ops(SVCXPRT
*);
71 static bool_t
svc_raw_control(SVCXPRT
*, const u_int
, void *);
73 char *__rpc_rawcombuf
= NULL
;
78 struct svc_raw_private
*srp
;
79 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
81 mutex_lock(&svcraw_lock
);
82 srp
= svc_raw_private
;
84 srp
= (struct svc_raw_private
*)calloc(1, sizeof (*srp
));
86 mutex_unlock(&svcraw_lock
);
89 if (__rpc_rawcombuf
== NULL
)
90 __rpc_rawcombuf
= calloc(UDPMSGSIZE
, sizeof (char));
91 srp
->raw_buf
= __rpc_rawcombuf
; /* Share it with the client */
92 svc_raw_private
= srp
;
94 srp
->server
.xp_fd
= FD_SETSIZE
;
95 srp
->server
.xp_port
= 0;
96 srp
->server
.xp_p3
= NULL
;
97 svc_raw_ops(&srp
->server
);
98 srp
->server
.xp_verf
.oa_base
= srp
->verf_body
;
99 xdrmem_create(&srp
->xdr_stream
, srp
->raw_buf
, UDPMSGSIZE
, XDR_DECODE
);
100 xprt_register(&srp
->server
);
101 mutex_unlock(&svcraw_lock
);
102 return (&srp
->server
);
106 static enum xprt_stat
108 SVCXPRT
*xprt
; /* args needed to satisfy ANSI-C typechecking */
115 svc_raw_recv(xprt
, msg
)
119 struct svc_raw_private
*srp
;
122 mutex_lock(&svcraw_lock
);
123 srp
= svc_raw_private
;
125 mutex_unlock(&svcraw_lock
);
128 mutex_unlock(&svcraw_lock
);
130 xdrs
= &srp
->xdr_stream
;
131 xdrs
->x_op
= XDR_DECODE
;
132 (void) XDR_SETPOS(xdrs
, 0);
133 if (! xdr_callmsg(xdrs
, msg
)) {
141 svc_raw_reply(xprt
, msg
)
145 struct svc_raw_private
*srp
;
148 mutex_lock(&svcraw_lock
);
149 srp
= svc_raw_private
;
151 mutex_unlock(&svcraw_lock
);
154 mutex_unlock(&svcraw_lock
);
156 xdrs
= &srp
->xdr_stream
;
157 xdrs
->x_op
= XDR_ENCODE
;
158 (void) XDR_SETPOS(xdrs
, 0);
159 if (! xdr_replymsg(xdrs
, msg
)) {
162 (void) XDR_GETPOS(xdrs
); /* called just for overhead */
168 svc_raw_getargs(xprt
, xdr_args
, args_ptr
)
173 struct svc_raw_private
*srp
;
175 mutex_lock(&svcraw_lock
);
176 srp
= svc_raw_private
;
178 mutex_unlock(&svcraw_lock
);
181 mutex_unlock(&svcraw_lock
);
182 return (*xdr_args
)(&srp
->xdr_stream
, args_ptr
);
187 svc_raw_freeargs(xprt
, xdr_args
, args_ptr
)
192 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
);
203 xdrs
= &srp
->xdr_stream
;
204 xdrs
->x_op
= XDR_FREE
;
205 return (*xdr_args
)(xdrs
, args_ptr
);
210 svc_raw_destroy(xprt
)
217 svc_raw_control(xprt
, rq
, in
)
229 static struct xp_ops ops
;
230 static struct xp_ops2 ops2
;
231 extern mutex_t ops_lock
;
233 /* VARIABLES PROTECTED BY ops_lock: ops */
235 mutex_lock(&ops_lock
);
236 if (ops
.xp_recv
== NULL
) {
237 ops
.xp_recv
= svc_raw_recv
;
238 ops
.xp_stat
= svc_raw_stat
;
239 ops
.xp_getargs
= svc_raw_getargs
;
240 ops
.xp_reply
= svc_raw_reply
;
241 ops
.xp_freeargs
= svc_raw_freeargs
;
242 ops
.xp_destroy
= svc_raw_destroy
;
243 ops2
.xp_control
= svc_raw_control
;
246 xprt
->xp_ops2
= &ops2
;
247 mutex_unlock(&ops_lock
);