svc_raw.c revision 1.3 1 /* $NetBSD: svc_raw.c,v 1.3 1995/02/25 03:01:59 cgd 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 #if defined(LIBC_SCCS) && !defined(lint)
33 /*static char *sccsid = "from: @(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
34 /*static char *sccsid = "from: @(#)svc_raw.c 2.1 88/07/29 4.0 RPCSRC";*/
35 static char *rcsid = "$NetBSD: svc_raw.c,v 1.3 1995/02/25 03:01:59 cgd Exp $";
36 #endif
37
38 /*
39 * svc_raw.c, This a toy for simple testing and timing.
40 * Interface to create an rpc client and server in the same UNIX process.
41 * This lets us similate rpc and get rpc (round trip) overhead, without
42 * any interference from the kernal.
43 *
44 * Copyright (C) 1984, Sun Microsystems, Inc.
45 */
46
47 #include <stdlib.h>
48 #include <rpc/rpc.h>
49
50
51 /*
52 * This is the "network" that we will be moving data over
53 */
54 static struct svcraw_private {
55 char _raw_buf[UDPMSGSIZE];
56 SVCXPRT server;
57 XDR xdr_stream;
58 char verf_body[MAX_AUTH_BYTES];
59 } *svcraw_private;
60
61 static bool_t svcraw_recv();
62 static enum xprt_stat svcraw_stat();
63 static bool_t svcraw_getargs();
64 static bool_t svcraw_reply();
65 static bool_t svcraw_freeargs();
66 static void svcraw_destroy();
67
68 static struct xp_ops server_ops = {
69 svcraw_recv,
70 svcraw_stat,
71 svcraw_getargs,
72 svcraw_reply,
73 svcraw_freeargs,
74 svcraw_destroy
75 };
76
77 SVCXPRT *
78 svcraw_create()
79 {
80 register struct svcraw_private *srp = svcraw_private;
81
82 if (srp == 0) {
83 srp = (struct svcraw_private *)calloc(1, sizeof (*srp));
84 if (srp == 0)
85 return (0);
86 }
87 srp->server.xp_sock = 0;
88 srp->server.xp_port = 0;
89 srp->server.xp_ops = &server_ops;
90 srp->server.xp_verf.oa_base = srp->verf_body;
91 xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
92 return (&srp->server);
93 }
94
95 static enum xprt_stat
96 svcraw_stat()
97 {
98
99 return (XPRT_IDLE);
100 }
101
102 static bool_t
103 svcraw_recv(xprt, msg)
104 SVCXPRT *xprt;
105 struct rpc_msg *msg;
106 {
107 register struct svcraw_private *srp = svcraw_private;
108 register XDR *xdrs;
109
110 if (srp == 0)
111 return (0);
112 xdrs = &srp->xdr_stream;
113 xdrs->x_op = XDR_DECODE;
114 XDR_SETPOS(xdrs, 0);
115 if (! xdr_callmsg(xdrs, msg))
116 return (FALSE);
117 return (TRUE);
118 }
119
120 static bool_t
121 svcraw_reply(xprt, msg)
122 SVCXPRT *xprt;
123 struct rpc_msg *msg;
124 {
125 register struct svcraw_private *srp = svcraw_private;
126 register XDR *xdrs;
127
128 if (srp == 0)
129 return (FALSE);
130 xdrs = &srp->xdr_stream;
131 xdrs->x_op = XDR_ENCODE;
132 XDR_SETPOS(xdrs, 0);
133 if (! xdr_replymsg(xdrs, msg))
134 return (FALSE);
135 (void)XDR_GETPOS(xdrs); /* called just for overhead */
136 return (TRUE);
137 }
138
139 static bool_t
140 svcraw_getargs(xprt, xdr_args, args_ptr)
141 SVCXPRT *xprt;
142 xdrproc_t xdr_args;
143 caddr_t args_ptr;
144 {
145 register struct svcraw_private *srp = svcraw_private;
146
147 if (srp == 0)
148 return (FALSE);
149 return ((*xdr_args)(&srp->xdr_stream, args_ptr));
150 }
151
152 static bool_t
153 svcraw_freeargs(xprt, xdr_args, args_ptr)
154 SVCXPRT *xprt;
155 xdrproc_t xdr_args;
156 caddr_t args_ptr;
157 {
158 register struct svcraw_private *srp = svcraw_private;
159 register XDR *xdrs;
160
161 if (srp == 0)
162 return (FALSE);
163 xdrs = &srp->xdr_stream;
164 xdrs->x_op = XDR_FREE;
165 return ((*xdr_args)(xdrs, args_ptr));
166 }
167
168 static void
169 svcraw_destroy()
170 {
171 }
172