1 /* $NetBSD: svc_raw.c,v 1.22 2012/03/20 17:14:50 matt 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 #include <sys/cdefs.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid
[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
42 __RCSID("$NetBSD: svc_raw.c,v 1.22 2012/03/20 17:14:50 matt Exp $");
47 * svc_raw.c, This a toy for simple testing and timing.
48 * Interface to create an rpc client and server in the same UNIX process.
49 * This lets us similate rpc and get rpc (round trip) overhead, without
50 * any interference from the kernel.
54 #include "namespace.h"
55 #include "reentrant.h"
57 #include <sys/types.h>
63 __weak_alias(svc_raw_create
,_svc_raw_create
)
67 #define UDPMSGSIZE 8800
71 * This is the "network" that we will be moving data over
73 static struct svc_raw_private
{
74 char *raw_buf
; /* should be shared with the cl handle */
77 char verf_body
[MAX_AUTH_BYTES
];
81 extern mutex_t svcraw_lock
;
84 static enum xprt_stat
svc_raw_stat(SVCXPRT
*);
85 static bool_t
svc_raw_recv(SVCXPRT
*, struct rpc_msg
*);
86 static bool_t
svc_raw_reply(SVCXPRT
*, struct rpc_msg
*);
87 static bool_t
svc_raw_getargs(SVCXPRT
*, xdrproc_t
, caddr_t
);
88 static bool_t
svc_raw_freeargs(SVCXPRT
*, xdrproc_t
, caddr_t
);
89 static void svc_raw_destroy(SVCXPRT
*);
90 static void svc_raw_ops(SVCXPRT
*);
91 static bool_t
svc_raw_control(SVCXPRT
*, const u_int
, void *);
93 char *__rpc_rawcombuf
= NULL
;
98 struct svc_raw_private
*srp
;
99 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
101 mutex_lock(&svcraw_lock
);
102 srp
= svc_raw_private
;
104 srp
= calloc(1, sizeof(*srp
));
107 if (__rpc_rawcombuf
== NULL
)
108 __rpc_rawcombuf
= malloc(UDPMSGSIZE
);
109 if (__rpc_rawcombuf
== NULL
)
111 srp
->raw_buf
= __rpc_rawcombuf
; /* Share it with the client */
112 svc_raw_private
= srp
;
114 srp
->server
.xp_fd
= FD_SETSIZE
;
115 srp
->server
.xp_port
= 0;
116 srp
->server
.xp_p3
= NULL
;
117 svc_raw_ops(&srp
->server
);
118 srp
->server
.xp_verf
.oa_base
= srp
->verf_body
;
119 xdrmem_create(&srp
->xdr_stream
, srp
->raw_buf
, UDPMSGSIZE
, XDR_DECODE
);
120 xprt_register(&srp
->server
);
121 mutex_unlock(&svcraw_lock
);
122 return (&srp
->server
);
126 mutex_unlock(&svcraw_lock
);
131 static enum xprt_stat
132 svc_raw_stat(SVCXPRT
*xprt
) /* args needed to satisfy ANSI-C typechecking */
139 svc_raw_recv(SVCXPRT
*xprt
, struct rpc_msg
*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(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
165 struct svc_raw_private
*srp
;
168 mutex_lock(&svcraw_lock
);
169 srp
= svc_raw_private
;
171 mutex_unlock(&svcraw_lock
);
174 mutex_unlock(&svcraw_lock
);
176 xdrs
= &srp
->xdr_stream
;
177 xdrs
->x_op
= XDR_ENCODE
;
178 (void) XDR_SETPOS(xdrs
, 0);
179 if (! xdr_replymsg(xdrs
, msg
)) {
182 (void) XDR_GETPOS(xdrs
); /* called just for overhead */
188 svc_raw_getargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
190 struct svc_raw_private
*srp
;
192 mutex_lock(&svcraw_lock
);
193 srp
= svc_raw_private
;
195 mutex_unlock(&svcraw_lock
);
198 mutex_unlock(&svcraw_lock
);
199 return (*xdr_args
)(&srp
->xdr_stream
, args_ptr
);
204 svc_raw_freeargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
206 struct svc_raw_private
*srp
;
209 mutex_lock(&svcraw_lock
);
210 srp
= svc_raw_private
;
212 mutex_unlock(&svcraw_lock
);
215 mutex_unlock(&svcraw_lock
);
217 xdrs
= &srp
->xdr_stream
;
218 xdrs
->x_op
= XDR_FREE
;
219 return (*xdr_args
)(xdrs
, args_ptr
);
224 svc_raw_destroy(SVCXPRT
*xprt
)
230 svc_raw_control(SVCXPRT
*xprt
, const u_int rq
, void *in
)
236 svc_raw_ops(SVCXPRT
*xprt
)
238 static struct xp_ops ops
;
239 static struct xp_ops2 ops2
;
241 extern mutex_t ops_lock
;
244 _DIAGASSERT(xprt
!= NULL
);
246 /* VARIABLES PROTECTED BY ops_lock: ops */
248 mutex_lock(&ops_lock
);
249 if (ops
.xp_recv
== NULL
) {
250 ops
.xp_recv
= svc_raw_recv
;
251 ops
.xp_stat
= svc_raw_stat
;
252 ops
.xp_getargs
= svc_raw_getargs
;
253 ops
.xp_reply
= svc_raw_reply
;
254 ops
.xp_freeargs
= svc_raw_freeargs
;
255 ops
.xp_destroy
= svc_raw_destroy
;
256 ops2
.xp_control
= svc_raw_control
;
259 xprt
->xp_ops2
= &ops2
;
260 mutex_unlock(&ops_lock
);