Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / rpc / svc_raw.c
1 #ifndef lint
2 static char sfs_svc_raw_id[] = "@(#)svc_raw.c     2.1     97/10/23";
3 #endif
4 /* @(#)svc_raw.c        2.1 88/07/29 4.0 RPCSRC */
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23 /*
24  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25  * unrestricted use provided that this legend is included on all tape
26  * media and as a part of the software program in whole or part.  Users
27  * may copy or modify Sun RPC without charge, but are not authorized
28  * to license or distribute it to anyone else except as part of a product or
29  * program developed by the user.
30  * 
31  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34  * 
35  * Sun RPC is provided with no support and without any obligation on the
36  * part of Sun Microsystems, Inc. to assist in its use, correction,
37  * modification or enhancement.
38  * 
39  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41  * OR ANY PART THEREOF.
42  * 
43  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44  * or profits or other special, indirect and consequential damages, even if
45  * Sun has been advised of the possibility of such damages.
46  * 
47  * Sun Microsystems, Inc.
48  * 2550 Garcia Avenue
49  * Mountain View, California  94043
50  */
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
53 #endif
54
55 /*
56  * svc_raw.c,   This a toy for simple testing and timing.
57  * Interface to create an rpc client and server in the same UNIX process.
58  * This lets us similate rpc and get rpc (round trip) overhead, without
59  * any interference from the kernal.
60  *
61  * Copyright (C) 1984, Sun Microsystems, Inc.
62  */
63
64 #include <stdio.h>
65 #include <stdlib.h>
66 #include <unistd.h>
67 #include "rpc/rpc.h"
68
69
70 /*
71  * This is the "network" that we will be moving data over
72  */
73 static struct svcraw_private {
74         char    _raw_buf[UDPMSGSIZE];
75         SVCXPRT server;
76         XDR     xdr_stream;
77         char    verf_body[MAX_AUTH_BYTES];
78 } *svcraw_private;
79
80 static bool_t           svcraw_recv(SVCXPRT *, struct rpc_msg *);
81 static enum xprt_stat   svcraw_stat(SVCXPRT *);
82 static bool_t           svcraw_getargs(SVCXPRT *, xdrproc_t, void *);
83 static bool_t           svcraw_reply(SVCXPRT *, struct rpc_msg *);
84 static bool_t           svcraw_freeargs(SVCXPRT *, xdrproc_t, void *);
85 static void             svcraw_destroy(SVCXPRT *);
86
87 static struct xp_ops server_ops = {
88         svcraw_recv,
89         svcraw_stat,
90         svcraw_getargs,
91         svcraw_reply,
92         svcraw_freeargs,
93         svcraw_destroy
94 };
95
96 SVCXPRT *
97 svcraw_create(void)
98 {
99         struct svcraw_private *srp = svcraw_private;
100
101         if (srp == 0) {
102                 srp = (struct svcraw_private *)calloc(1, sizeof (struct svcraw_private));
103                 if (srp == 0)
104                         return (0);
105         }
106         srp->server.xp_sock = 0;
107         srp->server.xp_port = 0;
108         srp->server.xp_ops = &server_ops;
109         srp->server.xp_verf.oa_base = srp->verf_body;
110         xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
111         return (&srp->server);
112 }
113
114 /* ARGSUSED */
115 static enum xprt_stat
116 svcraw_stat(SVCXPRT *x)
117 {
118
119         return (XPRT_IDLE);
120 }
121
122 /* ARGSUSED */
123 static bool_t
124 svcraw_recv(
125         SVCXPRT *xprt,
126         struct rpc_msg *msg)
127 {
128         struct svcraw_private *srp = svcraw_private;
129         XDR *xdrs;
130
131         if (srp == 0)
132                 return (0);
133         xdrs = &srp->xdr_stream;
134         xdrs->x_op = XDR_DECODE;
135         XDR_SETPOS(xdrs, 0);
136         if (! xdr_callmsg(xdrs, msg))
137                return (FALSE);
138         return (TRUE);
139 }
140
141 /* ARGSUSED */
142 static bool_t
143 svcraw_reply(
144         SVCXPRT *xprt,
145         struct rpc_msg *msg)
146 {
147         struct svcraw_private *srp = svcraw_private;
148         XDR *xdrs;
149
150         if (srp == 0)
151                 return (FALSE);
152         xdrs = &srp->xdr_stream;
153         xdrs->x_op = XDR_ENCODE;
154         XDR_SETPOS(xdrs, 0);
155         if (! xdr_replymsg(xdrs, msg))
156                return (FALSE);
157         (void)XDR_GETPOS(xdrs);  /* called just for overhead */
158         return (TRUE);
159 }
160
161 /* ARGSUSED */
162 static bool_t
163 svcraw_getargs(
164         SVCXPRT *xprt,
165         xdrproc_t xdr_args,
166         void *args_ptr)
167 {
168         struct svcraw_private *srp = svcraw_private;
169
170         if (srp == 0)
171                 return (FALSE);
172         return ((*xdr_args)(&srp->xdr_stream, args_ptr));
173 }
174
175 /* ARGSUSED */
176 static bool_t
177 svcraw_freeargs(
178         SVCXPRT *xprt,
179         xdrproc_t xdr_args,
180         void *args_ptr)
181
182         struct svcraw_private *srp = svcraw_private;
183         XDR *xdrs;
184
185         if (srp == 0)
186                 return (FALSE);
187         xdrs = &srp->xdr_stream;
188         xdrs->x_op = XDR_FREE;
189         return ((*xdr_args)(xdrs, args_ptr));
190
191
192 /* ARGSUSED */
193 static void
194 svcraw_destroy(SVCXPRT *x)
195 {
196 }