4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley
31 * 4.3 BSD under license from the Regents of the University of
36 * svc_raw.c, This is a toy for simple testing and timing.
37 * Interface to create an rpc client and server in the same UNIX process.
38 * This lets us simulate rpc and get rpc (round trip) overhead, without
39 * any interference from the kernal.
46 #include <sys/types.h>
50 #define UDPMSGSIZE 8800
54 * This is the "network" that we will be moving data over
56 static struct svc_raw_private
{
57 struct netbuf
*raw_netbuf
;
60 char verf_body
[MAX_AUTH_BYTES
];
63 static struct xp_ops
*svc_raw_ops();
64 extern mutex_t svcraw_lock
;
67 * This netbuf is shared with the raw client.
69 struct netbuf _rawcomnetbuf
;
74 struct svc_raw_private
*srp
;
76 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
77 (void) mutex_lock(&svcraw_lock
);
78 srp
= svc_raw_private
;
80 (void) mutex_unlock(&svcraw_lock
);
84 srp
= calloc(1, sizeof (*srp
));
86 syslog(LOG_ERR
, "svc_raw_create: out of memory");
88 (void) mutex_unlock(&svcraw_lock
);
92 srp
->raw_netbuf
= &_rawcomnetbuf
;
93 srp
->raw_netbuf
->buf
= malloc(UDPMSGSIZE
);
94 if (srp
->raw_netbuf
->buf
== NULL
) {
96 syslog(LOG_ERR
, "svc_raw_create: out of memory");
98 (void) mutex_unlock(&svcraw_lock
);
101 srp
->raw_netbuf
->maxlen
= UDPMSGSIZE
;
102 srp
->raw_netbuf
->len
= 0;
104 if ((srp
->server
= svc_xprt_alloc()) == NULL
) {
105 free(srp
->raw_netbuf
->buf
);
106 srp
->raw_netbuf
->buf
= NULL
;
107 srp
->raw_netbuf
->maxlen
= 0;
111 (void) mutex_unlock(&svcraw_lock
);
116 * By convention, using FD_SETSIZE as the pseudo file descriptor
118 srp
->server
->xp_fd
= FD_SETSIZE
;
119 srp
->server
->xp_port
= 0;
120 srp
->server
->xp_ops
= svc_raw_ops();
121 srp
->server
->xp_verf
.oa_base
= srp
->verf_body
;
122 xprt_register(srp
->server
);
124 svc_raw_private
= srp
;
126 (void) mutex_unlock(&svcraw_lock
);
127 return (srp
->server
);
131 static enum xprt_stat
132 svc_raw_stat(SVCXPRT
*xprt
)
139 svc_raw_recv(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
141 struct svc_raw_private
*srp
;
144 (void) mutex_lock(&svcraw_lock
);
145 srp
= svc_raw_private
;
147 (void) mutex_unlock(&svcraw_lock
);
150 (void) mutex_unlock(&svcraw_lock
);
152 xdrs
= &srp
->xdr_stream
;
154 xdrmem_create(xdrs
, srp
->raw_netbuf
->buf
, srp
->raw_netbuf
->len
,
157 if (!xdr_callmsg(xdrs
, msg
)) {
167 svc_raw_reply(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
169 struct svc_raw_private
*srp
;
173 (void) mutex_lock(&svcraw_lock
);
174 srp
= svc_raw_private
;
176 (void) mutex_unlock(&svcraw_lock
);
179 (void) mutex_unlock(&svcraw_lock
);
181 xdrs
= &srp
->xdr_stream
;
184 xdrmem_create(xdrs
, srp
->raw_netbuf
->buf
, srp
->raw_netbuf
->maxlen
,
187 start
= XDR_GETPOS(xdrs
);
188 if (!xdr_replymsg(xdrs
, msg
)) {
192 srp
->raw_netbuf
->len
= XDR_GETPOS(xdrs
) - start
;
199 svc_raw_getargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
201 struct svc_raw_private
*srp
;
203 (void) mutex_lock(&svcraw_lock
);
204 srp
= svc_raw_private
;
206 (void) mutex_unlock(&svcraw_lock
);
209 (void) mutex_unlock(&svcraw_lock
);
211 return ((*xdr_args
)(&srp
->xdr_stream
, args_ptr
));
216 svc_raw_freeargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
218 struct svc_raw_private
*srp
;
220 (void) mutex_lock(&svcraw_lock
);
221 srp
= svc_raw_private
;
223 (void) mutex_unlock(&svcraw_lock
);
226 (void) mutex_unlock(&svcraw_lock
);
228 XDR_DESTROY(&srp
->xdr_stream
);
230 xdr_free(xdr_args
, args_ptr
);
237 svc_raw_destroy(SVCXPRT
*xprt
)
243 svc_raw_control(SVCXPRT
*xprt
, const uint_t rq
, void *in
)
246 case SVCGET_XID
: /* fall through for now */
252 static struct xp_ops
*
255 static struct xp_ops ops
;
256 extern mutex_t ops_lock
;
258 /* VARIABLES PROTECTED BY ops_lock: ops */
260 (void) mutex_lock(&ops_lock
);
261 if (ops
.xp_recv
== NULL
) {
262 ops
.xp_recv
= svc_raw_recv
;
263 ops
.xp_stat
= svc_raw_stat
;
264 ops
.xp_getargs
= svc_raw_getargs
;
265 ops
.xp_reply
= svc_raw_reply
;
266 ops
.xp_freeargs
= svc_raw_freeargs
;
267 ops
.xp_destroy
= svc_raw_destroy
;
268 ops
.xp_control
= svc_raw_control
;
270 (void) mutex_unlock(&ops_lock
);