Debian Codegraph @

extra/tirpc/libtirpc-1.3.5/src/svc_raw.c

raw symbols SCIP
1
2 /*
3 * Copyright (c) 2009, Sun Microsystems, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * - Neither the name of Sun Microsystems, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29 /*
30 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
31 */
32
33 /*
34 * svc_raw.c, This a toy for simple testing and timing.
35 * Interface to create an rpc client and server in the same UNIX process.
36 * This lets us similate rpc and get rpc (round trip) overhead, without
37 * any interference from the kernel.
38 *
39 */
40 #include <pthread.h>
41 #include <reentrant.h>
42 #include <rpc/rpc.h>
43 #include <sys/types.h>
44 #include <rpc/raw.h>
45 #include <stdlib.h>
46
47 #ifndef UDPMSGSIZE
48 #define UDPMSGSIZE 8800
49 #endif
50
51 /*
52 * This is the "network" that we will be moving data over
53 */
54 static struct svc_raw_private {
55 char *raw_buf; /* should be shared with the cl handle */
56 SVCXPRT server;
57 XDR xdr_stream;
58 char verf_body[MAX_AUTH_BYTES];
59 } *svc_raw_private;
60
61 extern mutex_t svcraw_lock;
62
63 static enum xprt_stat svc_raw_stat(SVCXPRT *);
64 static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *);
65 static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *);
66 static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *);
67 static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *);
68 static void svc_raw_destroy(SVCXPRT *);
69 static void svc_raw_ops(SVCXPRT *);
70 static bool_t svc_raw_control(SVCXPRT *, const u_int, void *);
71
72 char *__rpc_rawcombuf = NULL;
73
74 SVCXPRT *
75 svc_raw_create()
76 {
77 struct svc_raw_private *srp;
78 SVCXPRT_EXT *ext = NULL;
79 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
80
81 mutex_lock(&svcraw_lock);
82 srp = svc_raw_private;
83 if (srp == NULL) {
84 srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
85 if (srp == NULL) {
86 mutex_unlock(&svcraw_lock);
87 return (NULL);
88 }
89 ext = mem_alloc(sizeof (*ext));
90 if (ext == NULL) {
91 free(srp);
92 mutex_unlock(&svcraw_lock);
93 return (NULL);
94 }
95 memset(ext, 0, sizeof (*ext));
96 srp->server.xp_p3 = ext;
97 if (__rpc_rawcombuf == NULL)
98 __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
99 srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
100 svc_raw_private = srp;
101 }
102 srp->server.xp_fd = FD_SETSIZE;
103 srp->server.xp_port = 0;
104 svc_flags(&srp->server) = 0;
105 svc_raw_ops(&srp->server);
106 srp->server.xp_verf.oa_base = srp->verf_body;
107 xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE);
108 xprt_register(&srp->server);
109 mutex_unlock(&svcraw_lock);
110 return (&srp->server);
111 }
112
113 /*ARGSUSED*/
114 static enum xprt_stat
115 svc_raw_stat(xprt)
116 SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */
117 {
118 return (XPRT_IDLE);
119 }
120
121 /*ARGSUSED*/
122 static bool_t
123 svc_raw_recv(xprt, msg)
124 SVCXPRT *xprt;
125 struct rpc_msg *msg;
126 {
127 struct svc_raw_private *srp;
128 XDR *xdrs;
129
130 mutex_lock(&svcraw_lock);
131 srp = svc_raw_private;
132 if (srp == NULL) {
133 mutex_unlock(&svcraw_lock);
134 return (FALSE);
135 }
136 mutex_unlock(&svcraw_lock);
137
138 xdrs = &srp->xdr_stream;
139 xdrs->x_op = XDR_DECODE;
140 (void) XDR_SETPOS(xdrs, 0);
141 if (! xdr_callmsg(xdrs, msg)) {
142 return (FALSE);
143 }
144 return (TRUE);
145 }
146
147 /*ARGSUSED*/
148 static bool_t
149 svc_raw_reply(xprt, msg)
150 SVCXPRT *xprt;
151 struct rpc_msg *msg;
152 {
153 struct svc_raw_private *srp;
154 XDR *xdrs;
155
156 mutex_lock(&svcraw_lock);
157 srp = svc_raw_private;
158 if (srp == NULL) {
159 mutex_unlock(&svcraw_lock);
160 return (FALSE);
161 }
162 mutex_unlock(&svcraw_lock);
163
164 xdrs = &srp->xdr_stream;
165 xdrs->x_op = XDR_ENCODE;
166 (void) XDR_SETPOS(xdrs, 0);
167 if (! xdr_replymsg(xdrs, msg)) {
168 return (FALSE);
169 }
170 (void) XDR_GETPOS(xdrs); /* called just for overhead */
171 return (TRUE);
172 }
173
174 /*ARGSUSED*/
175 static bool_t
176 svc_raw_getargs(xprt, xdr_args, args_ptr)
177 SVCXPRT *xprt;
178 xdrproc_t xdr_args;
179 void *args_ptr;
180 {
181 struct svc_raw_private *srp;
182
183 mutex_lock(&svcraw_lock);
184 srp = svc_raw_private;
185 if (srp == NULL) {
186 mutex_unlock(&svcraw_lock);
187 return (FALSE);
188 }
189 mutex_unlock(&svcraw_lock);
190 return (*xdr_args)(&srp->xdr_stream, args_ptr);
191 }
192
193 /*ARGSUSED*/
194 static bool_t
195 svc_raw_freeargs(xprt, xdr_args, args_ptr)
196 SVCXPRT *xprt;
197 xdrproc_t xdr_args;
198 void *args_ptr;
199 {
200 struct svc_raw_private *srp;
201 XDR *xdrs;
202
203 mutex_lock(&svcraw_lock);
204 srp = svc_raw_private;
205 if (srp == NULL) {
206 mutex_unlock(&svcraw_lock);
207 return (FALSE);
208 }
209 mutex_unlock(&svcraw_lock);
210
211 xdrs = &srp->xdr_stream;
212 xdrs->x_op = XDR_FREE;
213 return (*xdr_args)(xdrs, args_ptr);
214 }
215
216 /*ARGSUSED*/
217 static void
218 svc_raw_destroy(xprt)
219 SVCXPRT *xprt;
220 {
221 }
222
223 /*ARGSUSED*/
224 static bool_t
225 svc_raw_control(xprt, rq, in)
226 SVCXPRT *xprt;
227 const u_int rq;
228 void *in;
229 {
230 return (FALSE);
231 }
232
233 static void
234 svc_raw_ops(xprt)
235 SVCXPRT *xprt;
236 {
237 static struct xp_ops ops;
238 static struct xp_ops2 ops2;
239 extern mutex_t ops_lock;
240
241 /* VARIABLES PROTECTED BY ops_lock: ops */
242
243 mutex_lock(&ops_lock);
244 if (ops.xp_recv == NULL) {
245 ops.xp_recv = svc_raw_recv;
246 ops.xp_stat = svc_raw_stat;
247 ops.xp_getargs = svc_raw_getargs;
248 ops.xp_reply = svc_raw_reply;
249 ops.xp_freeargs = svc_raw_freeargs;
250 ops.xp_destroy = svc_raw_destroy;
251 ops2.xp_control = svc_raw_control;
252 }
253 xprt->xp_ops = &ops;
254 xprt->xp_ops2 = &ops2;
255 mutex_unlock(&ops_lock);
256 }