Add performance tests for strstr and strcasestr.
[glibc.git] / sunrpc / clnt_raw.c
blob74d90c8051aec892d80bace7e956c66d04f31078
1 /* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
2 /*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
32 #endif
35 * clnt_raw.c
37 * Copyright (C) 1984, Sun Microsystems, Inc.
39 * Memory based rpc for simple testing and timing.
40 * Interface to create an rpc client and server in the same process.
41 * This lets us simulate rpc and get round trip overhead, without
42 * any interference from the kernel.
45 #include <rpc/rpc.h>
46 #include <rpc/svc.h>
47 #include <rpc/xdr.h>
48 #include <libintl.h>
50 #define MCALL_MSG_SIZE 24
53 * This is the "network" we will be moving stuff over.
55 struct clntraw_private_s
57 CLIENT client_object;
58 XDR xdr_stream;
59 char _raw_buf[UDPMSGSIZE];
60 union
62 char msg[MCALL_MSG_SIZE];
63 u_long rm_xid;
64 } mashl_callmsg;
65 u_int mcnt;
67 #ifdef _RPC_THREAD_SAFE_
68 #define clntraw_private RPC_THREAD_VARIABLE(clntraw_private_s)
69 #else
70 static struct clntraw_private_s *clntraw_private;
71 #endif
73 static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
74 xdrproc_t, caddr_t, struct timeval);
75 static void clntraw_abort (void);
76 static void clntraw_geterr (CLIENT *, struct rpc_err *);
77 static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
78 static bool_t clntraw_control (CLIENT *, int, char *);
79 static void clntraw_destroy (CLIENT *);
81 static const struct clnt_ops client_ops =
83 clntraw_call,
84 clntraw_abort,
85 clntraw_geterr,
86 clntraw_freeres,
87 clntraw_destroy,
88 clntraw_control
92 * Create a client handle for memory based rpc.
94 CLIENT *
95 clntraw_create (u_long prog, u_long vers)
97 struct clntraw_private_s *clp = clntraw_private;
98 struct rpc_msg call_msg;
99 XDR *xdrs;
100 CLIENT *client;
102 if (clp == 0)
104 clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
105 if (clp == 0)
106 return (0);
107 clntraw_private = clp;
109 xdrs = &clp->xdr_stream;
110 client = &clp->client_object;
112 * pre-serialize the static part of the call msg and stash it away
114 call_msg.rm_direction = CALL;
115 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
116 call_msg.rm_call.cb_prog = prog;
117 call_msg.rm_call.cb_vers = vers;
118 INTUSE(xdrmem_create) (xdrs, clp->mashl_callmsg.msg, MCALL_MSG_SIZE,
119 XDR_ENCODE);
120 if (!INTUSE(xdr_callhdr) (xdrs, &call_msg))
122 perror (_ ("clnt_raw.c: fatal header serialization error"));
124 clp->mcnt = XDR_GETPOS (xdrs);
125 XDR_DESTROY (xdrs);
128 * Set xdrmem for client/server shared buffer
130 INTUSE(xdrmem_create) (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
133 * create client handle
135 client->cl_ops = (struct clnt_ops *) &client_ops;
136 client->cl_auth = INTUSE(authnone_create) ();
137 return client;
140 static enum clnt_stat
141 clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
142 CLIENT *h;
143 u_long proc;
144 xdrproc_t xargs;
145 caddr_t argsp;
146 xdrproc_t xresults;
147 caddr_t resultsp;
148 struct timeval timeout;
150 struct clntraw_private_s *clp = clntraw_private;
151 XDR *xdrs = &clp->xdr_stream;
152 struct rpc_msg msg;
153 enum clnt_stat status;
154 struct rpc_err error;
156 if (clp == NULL)
157 return RPC_FAILED;
158 call_again:
160 * send request
162 xdrs->x_op = XDR_ENCODE;
163 XDR_SETPOS (xdrs, 0);
164 /* Just checking the union definition to access rm_xid is correct. */
165 if (offsetof (struct rpc_msg, rm_xid) != 0)
166 abort ();
167 clp->mashl_callmsg.rm_xid++;
168 if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg.msg, clp->mcnt)) ||
169 (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
170 (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
171 (!(*xargs) (xdrs, argsp)))
173 return (RPC_CANTENCODEARGS);
175 (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
178 * We have to call server input routine here because this is
179 * all going on in one process. Yuk.
181 INTUSE(svc_getreq) (1);
184 * get results
186 xdrs->x_op = XDR_DECODE;
187 XDR_SETPOS (xdrs, 0);
188 msg.acpted_rply.ar_verf = _null_auth;
189 msg.acpted_rply.ar_results.where = resultsp;
190 msg.acpted_rply.ar_results.proc = xresults;
191 if (!INTUSE(xdr_replymsg) (xdrs, &msg))
192 return RPC_CANTDECODERES;
193 _seterr_reply (&msg, &error);
194 status = error.re_status;
196 if (status == RPC_SUCCESS)
198 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
200 status = RPC_AUTHERROR;
202 } /* end successful completion */
203 else
205 if (AUTH_REFRESH (h->cl_auth))
206 goto call_again;
207 } /* end of unsuccessful completion */
209 if (status == RPC_SUCCESS)
211 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
213 status = RPC_AUTHERROR;
215 if (msg.acpted_rply.ar_verf.oa_base != NULL)
217 xdrs->x_op = XDR_FREE;
218 (void) INTUSE(xdr_opaque_auth) (xdrs, &(msg.acpted_rply.ar_verf));
222 return status;
225 static void
226 clntraw_geterr (CLIENT *cl, struct rpc_err *err)
231 static bool_t
232 clntraw_freeres (cl, xdr_res, res_ptr)
233 CLIENT *cl;
234 xdrproc_t xdr_res;
235 caddr_t res_ptr;
237 struct clntraw_private_s *clp = clntraw_private;
238 XDR *xdrs = &clp->xdr_stream;
239 bool_t rval;
241 if (clp == NULL)
243 rval = (bool_t) RPC_FAILED;
244 return rval;
246 xdrs->x_op = XDR_FREE;
247 return (*xdr_res) (xdrs, res_ptr);
250 static void
251 clntraw_abort (void)
255 static bool_t
256 clntraw_control (CLIENT *cl, int i, char *c)
258 return FALSE;
261 static void
262 clntraw_destroy (CLIENT *cl)