1 /* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
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.
28 * Mountain View, California 94043
31 static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
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.
47 #include "rpc_private.h"
52 #define MCALL_MSG_SIZE 24
55 * This is the "network" we will be moving stuff over.
57 struct clntraw_private_s
61 char _raw_buf[UDPMSGSIZE];
62 char mashl_callmsg[MCALL_MSG_SIZE];
65 #ifdef __UCLIBC_HAS_THREADS__
66 #define clntraw_private (*(struct clntraw_private_s **)&RPC_THREAD_VARIABLE(clntraw_private_s))
68 static struct clntraw_private_s *clntraw_private;
71 static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
72 xdrproc_t, caddr_t, struct timeval);
73 static void clntraw_abort (void);
74 static void clntraw_geterr (CLIENT *, struct rpc_err *);
75 static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
76 static bool_t clntraw_control (CLIENT *, int, char *);
77 static void clntraw_destroy (CLIENT *);
79 static const struct clnt_ops client_ops =
90 * Create a client handle for memory based rpc.
93 clntraw_create (u_long prog, u_long vers)
95 struct clntraw_private_s *clp = clntraw_private;
96 struct rpc_msg call_msg;
97 XDR *xdrs = &clp->xdr_stream;
98 CLIENT *client = &clp->client_object;
102 clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
105 clntraw_private = clp;
108 * pre-serialize the static part of the call msg and stash it away
110 call_msg.rm_direction = CALL;
111 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
112 call_msg.rm_call.cb_prog = prog;
113 call_msg.rm_call.cb_vers = vers;
114 xdrmem_create (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
115 if (!xdr_callhdr (xdrs, &call_msg))
117 perror (_ ("clnt_raw.c - Fatal header serialization error."));
119 clp->mcnt = XDR_GETPOS (xdrs);
123 * Set xdrmem for client/server shared buffer
125 xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
128 * create client handle
130 client->cl_ops = &client_ops;
131 client->cl_auth = authnone_create ();
135 static enum clnt_stat
136 clntraw_call (CLIENT *h, u_long proc, xdrproc_t xargs, caddr_t argsp,
137 xdrproc_t xresults, caddr_t resultsp,
138 struct timeval timeout attribute_unused)
140 struct clntraw_private_s *clp = clntraw_private;
141 XDR *xdrs = &clp->xdr_stream;
143 enum clnt_stat status;
144 struct rpc_err error;
152 xdrs->x_op = XDR_ENCODE;
153 XDR_SETPOS (xdrs, 0);
154 ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
155 if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
156 (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
157 (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
158 (!(*xargs) (xdrs, argsp)))
160 return (RPC_CANTENCODEARGS);
162 (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
165 * We have to call server input routine here because this is
166 * all going on in one process. Yuk.
173 xdrs->x_op = XDR_DECODE;
174 XDR_SETPOS (xdrs, 0);
175 msg.acpted_rply.ar_verf = _null_auth;
176 msg.acpted_rply.ar_results.where = resultsp;
177 msg.acpted_rply.ar_results.proc = xresults;
178 if (!xdr_replymsg (xdrs, &msg))
179 return RPC_CANTDECODERES;
180 _seterr_reply (&msg, &error);
181 status = error.re_status;
183 if (status == RPC_SUCCESS)
185 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
187 status = RPC_AUTHERROR;
189 } /* end successful completion */
192 if (AUTH_REFRESH (h->cl_auth))
194 } /* end of unsuccessful completion */
196 if (status == RPC_SUCCESS)
198 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
200 status = RPC_AUTHERROR;
202 if (msg.acpted_rply.ar_verf.oa_base != NULL)
204 xdrs->x_op = XDR_FREE;
205 (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
213 clntraw_geterr (CLIENT *cl attribute_unused, struct rpc_err *err attribute_unused)
219 clntraw_freeres (CLIENT *cl attribute_unused, xdrproc_t xdr_res, caddr_t res_ptr)
221 struct clntraw_private_s *clp = clntraw_private;
222 XDR *xdrs = &clp->xdr_stream;
227 rval = (bool_t) RPC_FAILED;
230 xdrs->x_op = XDR_FREE;
231 return (*xdr_res) (xdrs, res_ptr);
240 clntraw_control (CLIENT *cl attribute_unused, int i attribute_unused, char *c attribute_unused)
246 clntraw_destroy (CLIENT *cl attribute_unused)