ReactOS  0.4.14-dev-317-g96040ec
svc_raw.c
Go to the documentation of this file.
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 <wintirpc.h>
41 //#include <pthread.h>
42 #include <reentrant.h>
43 #include <rpc/rpc.h>
44 #include <sys/types.h>
45 #include <rpc/raw.h>
46 #include <stdlib.h>
47 
48 #ifndef UDPMSGSIZE
49 #define UDPMSGSIZE 8800
50 #endif
51 
52 /*
53  * This is the "network" that we will be moving data over
54  */
55 static struct svc_raw_private {
56  char *raw_buf; /* should be shared with the cl handle */
61 
62 extern mutex_t svcraw_lock;
63 
64 static enum xprt_stat svc_raw_stat(SVCXPRT *);
65 static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *);
66 static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *);
67 static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *);
68 static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *);
69 static void svc_raw_destroy(SVCXPRT *);
70 static void svc_raw_ops(SVCXPRT *);
71 static bool_t svc_raw_control(SVCXPRT *, const u_int, void *);
72 
74 
75 SVCXPRT *
77 {
78  struct svc_raw_private *srp;
79 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
80 
82  srp = svc_raw_private;
83  if (srp == NULL) {
84  srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
85  if (srp == NULL) {
87  return (NULL);
88  }
89  if (__rpc_rawcombuf == NULL)
90  __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
91  srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
92  svc_raw_private = srp;
93  }
94  srp->server.xp_fd = FD_SETSIZE;
95  srp->server.xp_port = 0;
96  srp->server.xp_p3 = NULL;
97  svc_raw_ops(&srp->server);
98  srp->server.xp_verf.oa_base = srp->verf_body;
100  xprt_register(&srp->server);
102  return (&srp->server);
103 }
104 
105 /*ARGSUSED*/
106 static enum xprt_stat
108 SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */
109 {
110  return (XPRT_IDLE);
111 }
112 
113 /*ARGSUSED*/
114 static bool_t
116  SVCXPRT *xprt;
117  struct rpc_msg *msg;
118 {
119  struct svc_raw_private *srp;
120  XDR *xdrs;
121 
123  srp = svc_raw_private;
124  if (srp == NULL) {
126  return (FALSE);
127  }
129 
130  xdrs = &srp->xdr_stream;
131  xdrs->x_op = XDR_DECODE;
132  (void) XDR_SETPOS(xdrs, 0);
133  if (! xdr_callmsg(xdrs, msg)) {
134  return (FALSE);
135  }
136  return (TRUE);
137 }
138 
139 /*ARGSUSED*/
140 static bool_t
142  SVCXPRT *xprt;
143  struct rpc_msg *msg;
144 {
145  struct svc_raw_private *srp;
146  XDR *xdrs;
147 
149  srp = svc_raw_private;
150  if (srp == NULL) {
152  return (FALSE);
153  }
155 
156  xdrs = &srp->xdr_stream;
157  xdrs->x_op = XDR_ENCODE;
158  (void) XDR_SETPOS(xdrs, 0);
159  if (! xdr_replymsg(xdrs, msg)) {
160  return (FALSE);
161  }
162  (void) XDR_GETPOS(xdrs); /* called just for overhead */
163  return (TRUE);
164 }
165 
166 /*ARGSUSED*/
167 static bool_t
168 svc_raw_getargs(xprt, xdr_args, args_ptr)
169  SVCXPRT *xprt;
170  xdrproc_t xdr_args;
171  void *args_ptr;
172 {
173  struct svc_raw_private *srp;
174 
176  srp = svc_raw_private;
177  if (srp == NULL) {
179  return (FALSE);
180  }
182  return (*xdr_args)(&srp->xdr_stream, args_ptr);
183 }
184 
185 /*ARGSUSED*/
186 static bool_t
187 svc_raw_freeargs(xprt, xdr_args, args_ptr)
188  SVCXPRT *xprt;
189  xdrproc_t xdr_args;
190  void *args_ptr;
191 {
192  struct svc_raw_private *srp;
193  XDR *xdrs;
194 
196  srp = svc_raw_private;
197  if (srp == NULL) {
199  return (FALSE);
200  }
202 
203  xdrs = &srp->xdr_stream;
204  xdrs->x_op = XDR_FREE;
205  return (*xdr_args)(xdrs, args_ptr);
206 }
207 
208 /*ARGSUSED*/
209 static void
211 SVCXPRT *xprt;
212 {
213 }
214 
215 /*ARGSUSED*/
216 static bool_t
217 svc_raw_control(xprt, rq, in)
218  SVCXPRT *xprt;
219  const u_int rq;
220  void *in;
221 {
222  return (FALSE);
223 }
224 
225 static void
227  SVCXPRT *xprt;
228 {
229  static struct xp_ops ops;
230  static struct xp_ops2 ops2;
231  extern mutex_t ops_lock;
232 
233 /* VARIABLES PROTECTED BY ops_lock: ops */
234 
236  if (ops.xp_recv == NULL) {
237  ops.xp_recv = svc_raw_recv;
238  ops.xp_stat = svc_raw_stat;
239  ops.xp_getargs = svc_raw_getargs;
240  ops.xp_reply = svc_raw_reply;
241  ops.xp_freeargs = svc_raw_freeargs;
242  ops.xp_destroy = svc_raw_destroy;
243  ops2.xp_control = svc_raw_control;
244  }
245  xprt->xp_ops = &ops;
246  xprt->xp_ops2 = &ops2;
248 }
XDR xdr_stream
Definition: svc_raw.c:58
#define MAX_AUTH_BYTES
Definition: auth.h:77
#define TRUE
Definition: types.h:120
xprt_stat
Definition: svc.h:81
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
mutex_t ops_lock
Definition: mt_misc.c:71
static void svc_raw_destroy(SVCXPRT *)
Definition: svc_raw.c:210
int32_t bool_t
Definition: types.h:101
u_short xp_port
Definition: svc.h:92
Definition: svc.h:84
static void svc_raw_ops(SVCXPRT *)
Definition: svc_raw.c:226
Definition: xdr.h:103
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
static struct svc_raw_private * svc_raw_private
smooth NULL
Definition: ftsmooth.c:416
mutex_t svcraw_lock
Definition: mt_misc.c:83
const struct __rpc_svcxprt::xp_ops * xp_ops
bool_t xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg)
Definition: rpc_callmsg.c:50
#define FD_SETSIZE
Definition: winsock.h:50
SOCKET xp_fd
Definition: svc.h:91
void xprt_register(SVCXPRT *xprt)
Definition: svc.c:97
enum xdr_op x_op
Definition: xdr.h:104
char * raw_buf
Definition: svc_raw.c:56
SVCXPRT * svc_raw_create()
Definition: svc_raw.c:76
char * __rpc_rawcombuf
Definition: svc_raw.c:73
Definition: xdr.h:85
static bool_t svc_raw_control(SVCXPRT *, const u_int, void *)
Definition: svc_raw.c:217
static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *)
Definition: svc_raw.c:168
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
GLuint in
Definition: glext.h:9616
SVCXPRT server
Definition: svc_raw.c:57
UINT32 u_int
Definition: types.h:82
char verf_body[MAX_AUTH_BYTES]
Definition: svc_raw.c:59
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *)
Definition: svc_raw.c:141
static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *)
Definition: svc_raw.c:115
#define msg(x)
Definition: auth_time.c:54
Definition: xdr.h:87
#define calloc
Definition: rosglue.h:14
struct opaque_auth xp_verf
Definition: svc.h:121
Definition: xdr.h:86
void * xp_p3
Definition: svc.h:125
static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *)
Definition: svc_raw.c:187
#define UDPMSGSIZE
Definition: svc_raw.c:49
Definition: module.h:446
static enum xprt_stat svc_raw_stat(SVCXPRT *)
Definition: svc_raw.c:107
bool_t xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
Definition: rpc_prot.c:188
const struct __rpc_svcxprt::xp_ops2 * xp_ops2