svc_raw.c revision 1.6 1 /* $NetBSD: svc_raw.c,v 1.6 1998/02/10 04:54:52 lukem Exp $ */
2
3 /*
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
10 *
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 *
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
18 *
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
22 *
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
26 *
27 * Sun Microsystems, Inc.
28 * 2550 Garcia Avenue
29 * Mountain View, California 94043
30 */
31
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 #if 0
35 static char *sccsid = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
36 static char *sccsid = "@(#)svc_raw.c 2.1 88/07/29 4.0 RPCSRC";
37 #else
38 __RCSID("$NetBSD: svc_raw.c,v 1.6 1998/02/10 04:54:52 lukem Exp $");
39 #endif
40 #endif
41
42 /*
43 * svc_raw.c, This a toy for simple testing and timing.
44 * Interface to create an rpc client and server in the same UNIX process.
45 * This lets us similate rpc and get rpc (round trip) overhead, without
46 * any interference from the kernal.
47 *
48 * Copyright (C) 1984, Sun Microsystems, Inc.
49 */
50
51 #include "namespace.h"
52
53 #include <stdlib.h>
54
55 #include <rpc/rpc.h>
56
57 #ifdef __weak_alias
58 __weak_alias(svcraw_create,_svcraw_create);
59 #endif
60
61 /*
62 * This is the "network" that we will be moving data over
63 */
64 static struct svcraw_private {
65 char _raw_buf[UDPMSGSIZE];
66 SVCXPRT server;
67 XDR xdr_stream;
68 char verf_body[MAX_AUTH_BYTES];
69 } *svcraw_private;
70
71 static enum xprt_stat svcraw_stat __P((SVCXPRT *));
72 static bool_t svcraw_recv __P((SVCXPRT *, struct rpc_msg *));
73 static bool_t svcraw_reply __P((SVCXPRT *, struct rpc_msg *));
74 static bool_t svcraw_getargs __P((SVCXPRT *, xdrproc_t, caddr_t));
75 static bool_t svcraw_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t));
76 static void svcraw_destroy __P((SVCXPRT *));
77
78 static struct xp_ops server_ops = {
79 svcraw_recv,
80 svcraw_stat,
81 svcraw_getargs,
82 svcraw_reply,
83 svcraw_freeargs,
84 svcraw_destroy
85 };
86
87 SVCXPRT *
88 svcraw_create()
89 {
90 struct svcraw_private *srp = svcraw_private;
91
92 if (srp == NULL) {
93 srp = (struct svcraw_private *)calloc(1, sizeof (*srp));
94 if (srp == NULL)
95 return (NULL);
96 }
97 srp->server.xp_sock = 0;
98 srp->server.xp_port = 0;
99 srp->server.xp_ops = &server_ops;
100 srp->server.xp_verf.oa_base = srp->verf_body;
101 xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
102 return (&srp->server);
103 }
104
105 /*ARGSUSED*/
106 static enum xprt_stat
107 svcraw_stat(xprt)
108 SVCXPRT *xprt;
109 {
110
111 return (XPRT_IDLE);
112 }
113
114 static bool_t
115 svcraw_recv(xprt, msg)
116 SVCXPRT *xprt;
117 struct rpc_msg *msg;
118 {
119 struct svcraw_private *srp = svcraw_private;
120 XDR *xdrs;
121
122 if (srp == NULL)
123 return (FALSE);
124 xdrs = &srp->xdr_stream;
125 xdrs->x_op = XDR_DECODE;
126 XDR_SETPOS(xdrs, 0);
127 if (! xdr_callmsg(xdrs, msg))
128 return (FALSE);
129 return (TRUE);
130 }
131
132 static bool_t
133 svcraw_reply(xprt, msg)
134 SVCXPRT *xprt;
135 struct rpc_msg *msg;
136 {
137 struct svcraw_private *srp = svcraw_private;
138 XDR *xdrs;
139
140 if (srp == NULL)
141 return (FALSE);
142 xdrs = &srp->xdr_stream;
143 xdrs->x_op = XDR_ENCODE;
144 XDR_SETPOS(xdrs, 0);
145 if (! xdr_replymsg(xdrs, msg))
146 return (FALSE);
147 (void)XDR_GETPOS(xdrs); /* called just for overhead */
148 return (TRUE);
149 }
150
151 static bool_t
152 svcraw_getargs(xprt, xdr_args, args_ptr)
153 SVCXPRT *xprt;
154 xdrproc_t xdr_args;
155 caddr_t args_ptr;
156 {
157 struct svcraw_private *srp = svcraw_private;
158
159 if (srp == NULL)
160 return (FALSE);
161 return ((*xdr_args)(&srp->xdr_stream, args_ptr));
162 }
163
164 static bool_t
165 svcraw_freeargs(xprt, xdr_args, args_ptr)
166 SVCXPRT *xprt;
167 xdrproc_t xdr_args;
168 caddr_t args_ptr;
169 {
170 struct svcraw_private *srp = svcraw_private;
171 XDR *xdrs;
172
173 if (srp == NULL)
174 return (FALSE);
175 xdrs = &srp->xdr_stream;
176 xdrs->x_op = XDR_FREE;
177 return ((*xdr_args)(xdrs, args_ptr));
178 }
179
180 /*ARGSUSED*/
181 static void
182 svcraw_destroy(xprt)
183 SVCXPRT *xprt;
184 {
185 }
186