OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [clnt_raw.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* @(#)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.
9
 *
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.
13
 *
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.
17
 *
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.
21
 *
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.
25
 *
26
 * Sun Microsystems, Inc.
27
 * 2550 Garcia Avenue
28
 * Mountain View, California  94043
29
 */
30
#if 0
31
static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
32
#endif
33
 
34
/*
35
 * clnt_raw.c
36
 *
37
 * Copyright (C) 1984, Sun Microsystems, Inc.
38
 *
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.
43
 */
44
 
45
#define __FORCE_GLIBC
46
#include <features.h>
47
#include "rpc_private.h"
48
#include <rpc/svc.h>
49
#include <rpc/xdr.h>
50
 
51
#define MCALL_MSG_SIZE 24
52
 
53
/*
54
 * This is the "network" we will be moving stuff over.
55
 */
56
struct clntraw_private_s
57
  {
58
    CLIENT client_object;
59
    XDR xdr_stream;
60
    char _raw_buf[UDPMSGSIZE];
61
    char mashl_callmsg[MCALL_MSG_SIZE];
62
    u_int mcnt;
63
  };
64
#ifdef __UCLIBC_HAS_THREADS__
65
#define clntraw_private ((struct clntraw_private_s *)RPC_THREAD_VARIABLE(clntraw_private_s))
66
#else
67
static struct clntraw_private_s *clntraw_private;
68
#endif
69
 
70
static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
71
                                    xdrproc_t, caddr_t, struct timeval);
72
static void clntraw_abort (void);
73
static void clntraw_geterr (CLIENT *, struct rpc_err *);
74
static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
75
static bool_t clntraw_control (CLIENT *, int, char *);
76
static void clntraw_destroy (CLIENT *);
77
 
78
static struct clnt_ops client_ops =
79
{
80
  clntraw_call,
81
  clntraw_abort,
82
  clntraw_geterr,
83
  clntraw_freeres,
84
  clntraw_destroy,
85
  clntraw_control
86
};
87
 
88
/*
89
 * Create a client handle for memory based rpc.
90
 */
91
CLIENT *
92
clntraw_create (u_long prog, u_long vers)
93
{
94
  struct clntraw_private_s *clp = clntraw_private;
95
  struct rpc_msg call_msg;
96
  XDR *xdrs = &clp->xdr_stream;
97
  CLIENT *client = &clp->client_object;
98
 
99
  if (clp == 0)
100
    {
101
      clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
102
      if (clp == 0)
103
        return (0);
104
      clntraw_private = clp;
105
    }
106
  /*
107
   * pre-serialize the static part of the call msg and stash it away
108
   */
109
  call_msg.rm_direction = CALL;
110
  call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
111
  call_msg.rm_call.cb_prog = prog;
112
  call_msg.rm_call.cb_vers = vers;
113
  xdrmem_create (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
114
  if (!xdr_callhdr (xdrs, &call_msg))
115
    {
116
      perror (_ ("clnt_raw.c - Fatal header serialization error."));
117
    }
118
  clp->mcnt = XDR_GETPOS (xdrs);
119
  XDR_DESTROY (xdrs);
120
 
121
  /*
122
   * Set xdrmem for client/server shared buffer
123
   */
124
  xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
125
 
126
  /*
127
   * create client handle
128
   */
129
  client->cl_ops = &client_ops;
130
  client->cl_auth = authnone_create ();
131
  return client;
132
}
133
 
134
static enum clnt_stat
135
clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
136
     CLIENT *h;
137
     u_long proc;
138
     xdrproc_t xargs;
139
     caddr_t argsp;
140
     xdrproc_t xresults;
141
     caddr_t resultsp;
142
     struct timeval timeout;
143
{
144
  struct clntraw_private_s *clp = clntraw_private;
145
  XDR *xdrs = &clp->xdr_stream;
146
  struct rpc_msg msg;
147
  enum clnt_stat status;
148
  struct rpc_err error;
149
 
150
  if (clp == NULL)
151
    return RPC_FAILED;
152
call_again:
153
  /*
154
   * send request
155
   */
156
  xdrs->x_op = XDR_ENCODE;
157
  XDR_SETPOS (xdrs, 0);
158
  ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
159
  if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
160
      (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
161
      (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
162
      (!(*xargs) (xdrs, argsp)))
163
    {
164
      return (RPC_CANTENCODEARGS);
165
    }
166
  (void) XDR_GETPOS (xdrs);     /* called just to cause overhead */
167
 
168
  /*
169
   * We have to call server input routine here because this is
170
   * all going on in one process. Yuk.
171
   */
172
  svc_getreq (1);
173
 
174
  /*
175
   * get results
176
   */
177
  xdrs->x_op = XDR_DECODE;
178
  XDR_SETPOS (xdrs, 0);
179
  msg.acpted_rply.ar_verf = _null_auth;
180
  msg.acpted_rply.ar_results.where = resultsp;
181
  msg.acpted_rply.ar_results.proc = xresults;
182
  if (!xdr_replymsg (xdrs, &msg))
183
    return RPC_CANTDECODERES;
184
  _seterr_reply (&msg, &error);
185
  status = error.re_status;
186
 
187
  if (status == RPC_SUCCESS)
188
    {
189
      if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
190
        {
191
          status = RPC_AUTHERROR;
192
        }
193
    }                           /* end successful completion */
194
  else
195
    {
196
      if (AUTH_REFRESH (h->cl_auth))
197
        goto call_again;
198
    }                           /* end of unsuccessful completion */
199
 
200
  if (status == RPC_SUCCESS)
201
    {
202
      if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
203
        {
204
          status = RPC_AUTHERROR;
205
        }
206
      if (msg.acpted_rply.ar_verf.oa_base != NULL)
207
        {
208
          xdrs->x_op = XDR_FREE;
209
          (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
210
        }
211
    }
212
 
213
  return status;
214
}
215
 
216
static void
217
clntraw_geterr (CLIENT *cl, struct rpc_err *err)
218
{
219
}
220
 
221
 
222
static bool_t
223
clntraw_freeres (cl, xdr_res, res_ptr)
224
     CLIENT *cl;
225
     xdrproc_t xdr_res;
226
     caddr_t res_ptr;
227
{
228
  struct clntraw_private_s *clp = clntraw_private;
229
  XDR *xdrs = &clp->xdr_stream;
230
  bool_t rval;
231
 
232
  if (clp == NULL)
233
    {
234
      rval = (bool_t) RPC_FAILED;
235
      return rval;
236
    }
237
  xdrs->x_op = XDR_FREE;
238
  return (*xdr_res) (xdrs, res_ptr);
239
}
240
 
241
static void
242
clntraw_abort (void)
243
{
244
}
245
 
246
static bool_t
247
clntraw_control (CLIENT *cl, int i, char *c)
248
{
249
  return FALSE;
250
}
251
 
252
static void
253
clntraw_destroy (CLIENT *cl)
254
{
255
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.