]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | /* |
2 | * svc_raw.c, This a toy for simple testing and timing. | |
3 | * Interface to create an rpc client and server in the same UNIX process. | |
6d52618b UD |
4 | * This lets us simulate rpc and get rpc (round trip) overhead, without |
5 | * any interference from the kernel. | |
28f540f4 | 6 | * |
a7ab6ec8 UD |
7 | * Copyright (c) 2010, Oracle America, Inc. |
8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions are | |
11 | * met: | |
12 | * | |
13 | * * Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | |
15 | * * Redistributions in binary form must reproduce the above | |
16 | * copyright notice, this list of conditions and the following | |
17 | * disclaimer in the documentation and/or other materials | |
18 | * provided with the distribution. | |
19 | * * Neither the name of the "Oracle America, Inc." nor the names of its | |
20 | * contributors may be used to endorse or promote products derived | |
21 | * from this software without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
27 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
30 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
32 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28f540f4 RM |
35 | */ |
36 | ||
37 | #include <rpc/rpc.h> | |
e7fd8a39 | 38 | #include <rpc/svc.h> |
28f540f4 RM |
39 | |
40 | /* | |
41 | * This is the "network" that we will be moving data over | |
42 | */ | |
f1e4a4a4 | 43 | struct svcraw_private_s |
e7fd8a39 UD |
44 | { |
45 | char _raw_buf[UDPMSGSIZE]; | |
46 | SVCXPRT server; | |
47 | XDR xdr_stream; | |
48 | char verf_body[MAX_AUTH_BYTES]; | |
f1e4a4a4 UD |
49 | }; |
50 | #ifdef _RPC_THREAD_SAFE_ | |
1bc1a2b9 | 51 | #define svcraw_private RPC_THREAD_VARIABLE(svcraw_private_s) |
f1e4a4a4 UD |
52 | #else |
53 | static struct svcraw_private_s *svcraw_private; | |
54 | #endif | |
e7fd8a39 UD |
55 | |
56 | static bool_t svcraw_recv (SVCXPRT *, struct rpc_msg *); | |
57 | static enum xprt_stat svcraw_stat (SVCXPRT *); | |
58 | static bool_t svcraw_getargs (SVCXPRT *, xdrproc_t, caddr_t); | |
59 | static bool_t svcraw_reply (SVCXPRT *, struct rpc_msg *); | |
60 | static bool_t svcraw_freeargs (SVCXPRT *, xdrproc_t, caddr_t); | |
61 | static void svcraw_destroy (SVCXPRT *); | |
62 | ||
31d7b14c | 63 | static const struct xp_ops server_ops = |
e7fd8a39 UD |
64 | { |
65 | svcraw_recv, | |
66 | svcraw_stat, | |
67 | svcraw_getargs, | |
68 | svcraw_reply, | |
69 | svcraw_freeargs, | |
70 | svcraw_destroy | |
28f540f4 RM |
71 | }; |
72 | ||
73 | SVCXPRT * | |
e7fd8a39 | 74 | svcraw_create (void) |
28f540f4 | 75 | { |
f1e4a4a4 | 76 | struct svcraw_private_s *srp = svcraw_private; |
e7fd8a39 UD |
77 | |
78 | if (srp == 0) | |
79 | { | |
f1e4a4a4 | 80 | srp = (struct svcraw_private_s *) calloc (1, sizeof (*srp)); |
e7fd8a39 UD |
81 | if (srp == 0) |
82 | return NULL; | |
83 | } | |
84 | srp->server.xp_sock = 0; | |
85 | srp->server.xp_port = 0; | |
31d7b14c | 86 | srp->server.xp_ops = (struct xp_ops *) &server_ops; |
e7fd8a39 | 87 | srp->server.xp_verf.oa_base = srp->verf_body; |
7b57bfe5 | 88 | xdrmem_create (&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE); |
e7fd8a39 | 89 | return &srp->server; |
28f540f4 | 90 | } |
021db4be | 91 | libc_hidden_nolink_sunrpc (svcraw_create, GLIBC_2_0) |
28f540f4 RM |
92 | |
93 | static enum xprt_stat | |
e7fd8a39 | 94 | svcraw_stat (SVCXPRT *xprt) |
28f540f4 | 95 | { |
e7fd8a39 | 96 | return XPRT_IDLE; |
28f540f4 RM |
97 | } |
98 | ||
99 | static bool_t | |
9d46370c | 100 | svcraw_recv (SVCXPRT *xprt, struct rpc_msg *msg) |
28f540f4 | 101 | { |
f1e4a4a4 | 102 | struct svcraw_private_s *srp = svcraw_private; |
e7fd8a39 UD |
103 | XDR *xdrs; |
104 | ||
105 | if (srp == 0) | |
106 | return FALSE; | |
107 | xdrs = &srp->xdr_stream; | |
108 | xdrs->x_op = XDR_DECODE; | |
109 | XDR_SETPOS (xdrs, 0); | |
7b57bfe5 | 110 | if (!xdr_callmsg (xdrs, msg)) |
e7fd8a39 UD |
111 | return FALSE; |
112 | return TRUE; | |
28f540f4 RM |
113 | } |
114 | ||
115 | static bool_t | |
e7fd8a39 | 116 | svcraw_reply (SVCXPRT *xprt, struct rpc_msg *msg) |
28f540f4 | 117 | { |
f1e4a4a4 | 118 | struct svcraw_private_s *srp = svcraw_private; |
e7fd8a39 UD |
119 | XDR *xdrs; |
120 | ||
121 | if (srp == 0) | |
122 | return FALSE; | |
123 | xdrs = &srp->xdr_stream; | |
124 | xdrs->x_op = XDR_ENCODE; | |
125 | XDR_SETPOS (xdrs, 0); | |
7b57bfe5 | 126 | if (!xdr_replymsg (xdrs, msg)) |
e7fd8a39 UD |
127 | return FALSE; |
128 | (void) XDR_GETPOS (xdrs); /* called just for overhead */ | |
129 | return TRUE; | |
28f540f4 RM |
130 | } |
131 | ||
132 | static bool_t | |
e7fd8a39 | 133 | svcraw_getargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) |
28f540f4 | 134 | { |
f1e4a4a4 | 135 | struct svcraw_private_s *srp = svcraw_private; |
28f540f4 | 136 | |
e7fd8a39 UD |
137 | if (srp == 0) |
138 | return FALSE; | |
139 | return (*xdr_args) (&srp->xdr_stream, args_ptr); | |
28f540f4 RM |
140 | } |
141 | ||
142 | static bool_t | |
e7fd8a39 | 143 | svcraw_freeargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) |
6d52618b | 144 | { |
f1e4a4a4 | 145 | struct svcraw_private_s *srp = svcraw_private; |
e7fd8a39 UD |
146 | XDR *xdrs; |
147 | ||
148 | if (srp == 0) | |
149 | return FALSE; | |
150 | xdrs = &srp->xdr_stream; | |
151 | xdrs->x_op = XDR_FREE; | |
152 | return (*xdr_args) (xdrs, args_ptr); | |
6d52618b | 153 | } |
28f540f4 RM |
154 | |
155 | static void | |
e7fd8a39 | 156 | svcraw_destroy (SVCXPRT *xprt) |
28f540f4 RM |
157 | { |
158 | } |