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