2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * @(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro
30 * @(#)svc_raw.c 1.16 94/04/24 SMI
31 * $NetBSD: svc_raw.c,v 1.14 2000/07/06 03:10:35 christos Exp $
32 * $FreeBSD: src/lib/libc/rpc/svc_raw.c,v 1.15 2006/02/27 22:10:59 deischen Exp $
33 * $DragonFly: src/lib/libc/rpc/svc_raw.c,v 1.4 2005/11/13 12:27:04 swildner Exp $
36 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
40 * svc_raw.c, This a toy for simple testing and timing.
41 * Interface to create an rpc client and server in the same UNIX process.
42 * This lets us similate rpc and get rpc (round trip) overhead, without
43 * any interference from the kernel.
47 #include "namespace.h"
48 #include "reentrant.h"
50 #include <sys/types.h>
53 #include "un-namespace.h"
57 #define UDPMSGSIZE 8800
61 * This is the "network" that we will be moving data over
63 static struct svc_raw_private
{
64 char *raw_buf
; /* should be shared with the cl handle */
67 char verf_body
[MAX_AUTH_BYTES
];
70 static enum xprt_stat
svc_raw_stat(SVCXPRT
*);
71 static bool_t
svc_raw_recv(SVCXPRT
*, struct rpc_msg
*);
72 static bool_t
svc_raw_reply(SVCXPRT
*, struct rpc_msg
*);
73 static bool_t
svc_raw_getargs(SVCXPRT
*, xdrproc_t
, void *);
74 static bool_t
svc_raw_freeargs(SVCXPRT
*, xdrproc_t
, void *);
75 static void svc_raw_destroy(SVCXPRT
*);
76 static void svc_raw_ops(SVCXPRT
*);
77 static bool_t
svc_raw_control(SVCXPRT
*, const u_int
, void *);
79 char *__rpc_rawcombuf
= NULL
;
84 struct svc_raw_private
*srp
;
85 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
87 mutex_lock(&svcraw_lock
);
88 srp
= svc_raw_private
;
90 srp
= (struct svc_raw_private
*)calloc(1, sizeof (*srp
));
92 mutex_unlock(&svcraw_lock
);
95 if (__rpc_rawcombuf
== NULL
)
96 __rpc_rawcombuf
= calloc(UDPMSGSIZE
, sizeof (char));
97 srp
->raw_buf
= __rpc_rawcombuf
; /* Share it with the client */
98 svc_raw_private
= srp
;
100 srp
->server
.xp_fd
= FD_SETSIZE
;
101 srp
->server
.xp_port
= 0;
102 srp
->server
.xp_p3
= NULL
;
103 svc_raw_ops(&srp
->server
);
104 srp
->server
.xp_verf
.oa_base
= srp
->verf_body
;
105 xdrmem_create(&srp
->xdr_stream
, srp
->raw_buf
, UDPMSGSIZE
, XDR_DECODE
);
106 xprt_register(&srp
->server
);
107 mutex_unlock(&svcraw_lock
);
108 return (&srp
->server
);
112 static enum xprt_stat
113 svc_raw_stat(SVCXPRT
*xprt
)
120 svc_raw_recv(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
122 struct svc_raw_private
*srp
;
125 mutex_lock(&svcraw_lock
);
126 srp
= svc_raw_private
;
128 mutex_unlock(&svcraw_lock
);
131 mutex_unlock(&svcraw_lock
);
133 xdrs
= &srp
->xdr_stream
;
134 xdrs
->x_op
= XDR_DECODE
;
136 if (! xdr_callmsg(xdrs
, msg
)) {
144 svc_raw_reply(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
146 struct svc_raw_private
*srp
;
149 mutex_lock(&svcraw_lock
);
150 srp
= svc_raw_private
;
152 mutex_unlock(&svcraw_lock
);
155 mutex_unlock(&svcraw_lock
);
157 xdrs
= &srp
->xdr_stream
;
158 xdrs
->x_op
= XDR_ENCODE
;
160 if (! xdr_replymsg(xdrs
, msg
)) {
163 XDR_GETPOS(xdrs
); /* called just for overhead */
169 svc_raw_getargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, void *args_ptr
)
171 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
);
180 return (*xdr_args
)(&srp
->xdr_stream
, args_ptr
);
185 svc_raw_freeargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, void *args_ptr
)
187 struct svc_raw_private
*srp
;
190 mutex_lock(&svcraw_lock
);
191 srp
= svc_raw_private
;
193 mutex_unlock(&svcraw_lock
);
196 mutex_unlock(&svcraw_lock
);
198 xdrs
= &srp
->xdr_stream
;
199 xdrs
->x_op
= XDR_FREE
;
200 return (*xdr_args
)(xdrs
, args_ptr
);
205 svc_raw_destroy(SVCXPRT
*xprt
)
211 svc_raw_control(SVCXPRT
*xprt
, const u_int rq
, void *in
)
217 svc_raw_ops(SVCXPRT
*xprt
)
219 static struct xp_ops ops
;
220 static struct xp_ops2 ops2
;
222 /* VARIABLES PROTECTED BY ops_lock: ops */
224 mutex_lock(&ops_lock
);
225 if (ops
.xp_recv
== NULL
) {
226 ops
.xp_recv
= svc_raw_recv
;
227 ops
.xp_stat
= svc_raw_stat
;
228 ops
.xp_getargs
= svc_raw_getargs
;
229 ops
.xp_reply
= svc_raw_reply
;
230 ops
.xp_freeargs
= svc_raw_freeargs
;
231 ops
.xp_destroy
= svc_raw_destroy
;
232 ops2
.xp_control
= svc_raw_control
;
235 xprt
->xp_ops2
= &ops2
;
236 mutex_unlock(&ops_lock
);