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
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * svc_raw.c, This a toy for simple testing and timing.
39 * Interface to create an rpc client and server in the same UNIX process.
40 * This lets us similate rpc and get rpc (round trip) overhead, without
41 * any interference from the kernal.
49 #include <sys/types.h>
54 #define UDPMSGSIZE 8800
58 * This is the "network" that we will be moving data over
60 static struct svc_raw_private
{
61 char *raw_buf
; /* should be shared with the cl handle */
64 char verf_body
[MAX_AUTH_BYTES
];
67 static struct xp_ops
*svc_raw_ops();
68 extern mutex_t svcraw_lock
;
75 struct svc_raw_private
*srp
;
76 bool_t flag1
= FALSE
, flag2
= FALSE
;
78 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
79 (void) mutex_lock(&svcraw_lock
);
80 srp
= svc_raw_private
;
82 srp
= calloc(1, sizeof (*srp
));
84 syslog(LOG_ERR
, "svc_raw_create: out of memory");
85 (void) mutex_unlock(&svcraw_lock
);
89 if (_rawcombuf
== NULL
) {
90 _rawcombuf
= calloc(UDPMSGSIZE
, sizeof (char));
91 if (_rawcombuf
== NULL
) {
93 syslog(LOG_ERR
, "svc_raw_create: "
95 (void) mutex_unlock(&svcraw_lock
);
100 srp
->raw_buf
= _rawcombuf
; /* Share it with the client */
101 svc_raw_private
= srp
;
103 if ((srp
->server
= svc_xprt_alloc()) == NULL
) {
105 free(svc_raw_private
->raw_buf
);
107 free(svc_raw_private
);
108 (void) mutex_unlock(&svcraw_lock
);
112 * By convention, using FD_SETSIZE as the psuedo file descriptor
114 srp
->server
->xp_fd
= FD_SETSIZE
;
115 srp
->server
->xp_port
= 0;
116 srp
->server
->xp_ops
= svc_raw_ops();
117 srp
->server
->xp_verf
.oa_base
= srp
->verf_body
;
118 xdrmem_create(&srp
->xdr_stream
, srp
->raw_buf
, UDPMSGSIZE
, XDR_DECODE
);
119 xprt_register(srp
->server
);
120 (void) mutex_unlock(&svcraw_lock
);
121 return (srp
->server
);
125 static enum xprt_stat
126 svc_raw_stat(SVCXPRT
*xprt
)
133 svc_raw_recv(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
135 struct svc_raw_private
*srp
;
138 (void) mutex_lock(&svcraw_lock
);
139 srp
= svc_raw_private
;
141 (void) mutex_unlock(&svcraw_lock
);
144 (void) mutex_unlock(&svcraw_lock
);
146 xdrs
= &srp
->xdr_stream
;
147 xdrs
->x_op
= XDR_DECODE
;
148 (void) XDR_SETPOS(xdrs
, 0);
149 return (xdr_callmsg(xdrs
, msg
));
154 svc_raw_reply(SVCXPRT
*xprt
, struct rpc_msg
*msg
)
156 struct svc_raw_private
*srp
;
159 (void) mutex_lock(&svcraw_lock
);
160 srp
= svc_raw_private
;
162 (void) mutex_unlock(&svcraw_lock
);
165 (void) mutex_unlock(&svcraw_lock
);
167 xdrs
= &srp
->xdr_stream
;
168 xdrs
->x_op
= XDR_ENCODE
;
169 (void) XDR_SETPOS(xdrs
, 0);
170 return (xdr_replymsg(xdrs
, msg
));
175 svc_raw_getargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
177 struct svc_raw_private
*srp
;
179 (void) mutex_lock(&svcraw_lock
);
180 srp
= svc_raw_private
;
182 (void) mutex_unlock(&svcraw_lock
);
185 (void) mutex_unlock(&svcraw_lock
);
186 return ((*xdr_args
)(&srp
->xdr_stream
, args_ptr
));
191 svc_raw_freeargs(SVCXPRT
*xprt
, xdrproc_t xdr_args
, caddr_t args_ptr
)
193 struct svc_raw_private
*srp
;
196 (void) mutex_lock(&svcraw_lock
);
197 srp
= svc_raw_private
;
199 (void) mutex_unlock(&svcraw_lock
);
202 (void) mutex_unlock(&svcraw_lock
);
204 xdrs
= &srp
->xdr_stream
;
205 xdrs
->x_op
= XDR_FREE
;
206 return ((*xdr_args
)(xdrs
, args_ptr
));
211 svc_raw_destroy(SVCXPRT
*xprt
)
217 svc_raw_control(SVCXPRT
*xprt
, const uint_t rq
, void *in
)
220 case SVCGET_XID
: /* fall through for now */
226 static struct xp_ops
*
229 static struct xp_ops ops
;
230 extern mutex_t ops_lock
;
232 /* VARIABLES PROTECTED BY ops_lock: ops */
234 (void) mutex_lock(&ops_lock
);
235 if (ops
.xp_recv
== NULL
) {
236 ops
.xp_recv
= svc_raw_recv
;
237 ops
.xp_stat
= svc_raw_stat
;
238 ops
.xp_getargs
= svc_raw_getargs
;
239 ops
.xp_reply
= svc_raw_reply
;
240 ops
.xp_freeargs
= svc_raw_freeargs
;
241 ops
.xp_destroy
= svc_raw_destroy
;
242 ops
.xp_control
= svc_raw_control
;
244 (void) mutex_unlock(&ops_lock
);