GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libc/rpc/svc_raw.c Lines: 0 41 0.0 %
Date: 2017-11-13 Branches: 0 16 0.0 %

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