Update.
[glibc.git] / sunrpc / clnt_raw.c
blob8ed589c93ddeb50af7384b26fdbc65088f2c64f4
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 static struct clntraw_private
57 CLIENT client_object;
58 XDR xdr_stream;
59 char _raw_buf[UDPMSGSIZE];
60 char mashl_callmsg[MCALL_MSG_SIZE];
61 u_int mcnt;
63 *clntraw_private;
65 static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
66 xdrproc_t, caddr_t, struct timeval);
67 static void clntraw_abort (void);
68 static void clntraw_geterr (CLIENT *, struct rpc_err *);
69 static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
70 static bool_t clntraw_control (CLIENT *, int, char *);
71 static void clntraw_destroy (CLIENT *);
73 static struct clnt_ops client_ops =
75 clntraw_call,
76 clntraw_abort,
77 clntraw_geterr,
78 clntraw_freeres,
79 clntraw_destroy,
80 clntraw_control
84 * Create a client handle for memory based rpc.
86 CLIENT *
87 clntraw_create (u_long prog, u_long vers)
89 struct clntraw_private *clp = clntraw_private;
90 struct rpc_msg call_msg;
91 XDR *xdrs = &clp->xdr_stream;
92 CLIENT *client = &clp->client_object;
94 if (clp == 0)
96 clp = (struct clntraw_private *) calloc (1, sizeof (*clp));
97 if (clp == 0)
98 return (0);
99 clntraw_private = clp;
102 * pre-serialize the static part of the call msg and stash it away
104 call_msg.rm_direction = CALL;
105 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
106 call_msg.rm_call.cb_prog = prog;
107 call_msg.rm_call.cb_vers = vers;
108 xdrmem_create (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
109 if (!xdr_callhdr (xdrs, &call_msg))
111 perror (_ ("clnt_raw.c - Fatal header serialization error."));
113 clp->mcnt = XDR_GETPOS (xdrs);
114 XDR_DESTROY (xdrs);
117 * Set xdrmem for client/server shared buffer
119 xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
122 * create client handle
124 client->cl_ops = &client_ops;
125 client->cl_auth = authnone_create ();
126 return client;
129 static enum clnt_stat
130 clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
131 CLIENT *h;
132 u_long proc;
133 xdrproc_t xargs;
134 caddr_t argsp;
135 xdrproc_t xresults;
136 caddr_t resultsp;
137 struct timeval timeout;
139 struct clntraw_private *clp = clntraw_private;
140 XDR *xdrs = &clp->xdr_stream;
141 struct rpc_msg msg;
142 enum clnt_stat status;
143 struct rpc_err error;
145 if (clp == NULL)
146 return RPC_FAILED;
147 call_again:
149 * send request
151 xdrs->x_op = XDR_ENCODE;
152 XDR_SETPOS (xdrs, 0);
153 ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
154 if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
155 (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
156 (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
157 (!(*xargs) (xdrs, argsp)))
159 return (RPC_CANTENCODEARGS);
161 (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
164 * We have to call server input routine here because this is
165 * all going on in one process. Yuk.
167 svc_getreq (1);
170 * get results
172 xdrs->x_op = XDR_DECODE;
173 XDR_SETPOS (xdrs, 0);
174 msg.acpted_rply.ar_verf = _null_auth;
175 msg.acpted_rply.ar_results.where = resultsp;
176 msg.acpted_rply.ar_results.proc = xresults;
177 if (!xdr_replymsg (xdrs, &msg))
178 return RPC_CANTDECODERES;
179 _seterr_reply (&msg, &error);
180 status = error.re_status;
182 if (status == RPC_SUCCESS)
184 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
186 status = RPC_AUTHERROR;
188 } /* end successful completion */
189 else
191 if (AUTH_REFRESH (h->cl_auth))
192 goto call_again;
193 } /* end of unsuccessful completion */
195 if (status == RPC_SUCCESS)
197 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
199 status = RPC_AUTHERROR;
201 if (msg.acpted_rply.ar_verf.oa_base != NULL)
203 xdrs->x_op = XDR_FREE;
204 (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
208 return status;
211 static void
212 clntraw_geterr (CLIENT *cl, struct rpc_err *err)
217 static bool_t
218 clntraw_freeres (cl, xdr_res, res_ptr)
219 CLIENT *cl;
220 xdrproc_t xdr_res;
221 caddr_t res_ptr;
223 struct clntraw_private *clp = clntraw_private;
224 XDR *xdrs = &clp->xdr_stream;
225 bool_t rval;
227 if (clp == NULL)
229 rval = (bool_t) RPC_FAILED;
230 return rval;
232 xdrs->x_op = XDR_FREE;
233 return (*xdr_res) (xdrs, res_ptr);
236 static void
237 clntraw_abort (void)
241 static bool_t
242 clntraw_control (CLIENT *cl, int i, char *c)
244 return FALSE;
247 static void
248 clntraw_destroy (CLIENT *cl)