Blame sunrpc/svc_raw.c

Packit Service 82fcde
/*
Packit Service 82fcde
 * svc_raw.c,   This a toy for simple testing and timing.
Packit Service 82fcde
 * Interface to create an rpc client and server in the same UNIX process.
Packit Service 82fcde
 * This lets us simulate rpc and get rpc (round trip) overhead, without
Packit Service 82fcde
 * any interference from the kernel.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Copyright (c) 2010, Oracle America, Inc.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Redistribution and use in source and binary forms, with or without
Packit Service 82fcde
 * modification, are permitted provided that the following conditions are
Packit Service 82fcde
 * met:
Packit Service 82fcde
 *
Packit Service 82fcde
 *     * Redistributions of source code must retain the above copyright
Packit Service 82fcde
 *       notice, this list of conditions and the following disclaimer.
Packit Service 82fcde
 *     * Redistributions in binary form must reproduce the above
Packit Service 82fcde
 *       copyright notice, this list of conditions and the following
Packit Service 82fcde
 *       disclaimer in the documentation and/or other materials
Packit Service 82fcde
 *       provided with the distribution.
Packit Service 82fcde
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit Service 82fcde
 *       contributors may be used to endorse or promote products derived
Packit Service 82fcde
 *       from this software without specific prior written permission.
Packit Service 82fcde
 *
Packit Service 82fcde
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 82fcde
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 82fcde
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit Service 82fcde
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit Service 82fcde
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit Service 82fcde
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 82fcde
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit Service 82fcde
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit Service 82fcde
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit Service 82fcde
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit Service 82fcde
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 82fcde
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 82fcde
 */
Packit Service 82fcde
Packit Service 82fcde
#include <rpc/rpc.h>
Packit Service 82fcde
#include <rpc/svc.h>
Packit Service 82fcde
#include <shlib-compat.h>
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * This is the "network" that we will be moving data over
Packit Service 82fcde
 */
Packit Service 82fcde
struct svcraw_private_s
Packit Service 82fcde
  {
Packit Service 82fcde
    char _raw_buf[UDPMSGSIZE];
Packit Service 82fcde
    SVCXPRT server;
Packit Service 82fcde
    XDR xdr_stream;
Packit Service 82fcde
    char verf_body[MAX_AUTH_BYTES];
Packit Service 82fcde
  };
Packit Service 82fcde
#define svcraw_private RPC_THREAD_VARIABLE(svcraw_private_s)
Packit Service 82fcde
Packit Service 82fcde
static bool_t svcraw_recv (SVCXPRT *, struct rpc_msg *);
Packit Service 82fcde
static enum xprt_stat svcraw_stat (SVCXPRT *);
Packit Service 82fcde
static bool_t svcraw_getargs (SVCXPRT *, xdrproc_t, caddr_t);
Packit Service 82fcde
static bool_t svcraw_reply (SVCXPRT *, struct rpc_msg *);
Packit Service 82fcde
static bool_t svcraw_freeargs (SVCXPRT *, xdrproc_t, caddr_t);
Packit Service 82fcde
static void svcraw_destroy (SVCXPRT *);
Packit Service 82fcde
Packit Service 82fcde
static const struct xp_ops server_ops =
Packit Service 82fcde
{
Packit Service 82fcde
  svcraw_recv,
Packit Service 82fcde
  svcraw_stat,
Packit Service 82fcde
  svcraw_getargs,
Packit Service 82fcde
  svcraw_reply,
Packit Service 82fcde
  svcraw_freeargs,
Packit Service 82fcde
  svcraw_destroy
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
SVCXPRT *
Packit Service 82fcde
svcraw_create (void)
Packit Service 82fcde
{
Packit Service 82fcde
  struct svcraw_private_s *srp = svcraw_private;
Packit Service 82fcde
Packit Service 82fcde
  if (srp == 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      srp = (struct svcraw_private_s *) calloc (1, sizeof (*srp));
Packit Service 82fcde
      if (srp == 0)
Packit Service 82fcde
	return NULL;
Packit Service 82fcde
    }
Packit Service 82fcde
  srp->server.xp_sock = 0;
Packit Service 82fcde
  srp->server.xp_port = 0;
Packit Service 82fcde
  srp->server.xp_ops = (struct xp_ops *) &server_ops;
Packit Service 82fcde
  srp->server.xp_verf.oa_base = srp->verf_body;
Packit Service 82fcde
  xdrmem_create (&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
Packit Service 82fcde
  return &srp->server;
Packit Service 82fcde
}
Packit Service 82fcde
libc_hidden_nolink_sunrpc (svcraw_create, GLIBC_2_0)
Packit Service 82fcde
Packit Service 82fcde
static enum xprt_stat
Packit Service 82fcde
svcraw_stat (SVCXPRT *xprt)
Packit Service 82fcde
{
Packit Service 82fcde
  return XPRT_IDLE;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static bool_t
Packit Service 82fcde
svcraw_recv (SVCXPRT *xprt, struct rpc_msg *msg)
Packit Service 82fcde
{
Packit Service 82fcde
  struct svcraw_private_s *srp = svcraw_private;
Packit Service 82fcde
  XDR *xdrs;
Packit Service 82fcde
Packit Service 82fcde
  if (srp == 0)
Packit Service 82fcde
    return FALSE;
Packit Service 82fcde
  xdrs = &srp->xdr_stream;
Packit Service 82fcde
  xdrs->x_op = XDR_DECODE;
Packit Service 82fcde
  XDR_SETPOS (xdrs, 0);
Packit Service 82fcde
  if (!xdr_callmsg (xdrs, msg))
Packit Service 82fcde
    return FALSE;
Packit Service 82fcde
  return TRUE;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static bool_t
Packit Service 82fcde
svcraw_reply (SVCXPRT *xprt, struct rpc_msg *msg)
Packit Service 82fcde
{
Packit Service 82fcde
  struct svcraw_private_s *srp = svcraw_private;
Packit Service 82fcde
  XDR *xdrs;
Packit Service 82fcde
Packit Service 82fcde
  if (srp == 0)
Packit Service 82fcde
    return FALSE;
Packit Service 82fcde
  xdrs = &srp->xdr_stream;
Packit Service 82fcde
  xdrs->x_op = XDR_ENCODE;
Packit Service 82fcde
  XDR_SETPOS (xdrs, 0);
Packit Service 82fcde
  if (!xdr_replymsg (xdrs, msg))
Packit Service 82fcde
    return FALSE;
Packit Service 82fcde
  (void) XDR_GETPOS (xdrs);	/* called just for overhead */
Packit Service 82fcde
  return TRUE;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static bool_t
Packit Service 82fcde
svcraw_getargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
Packit Service 82fcde
{
Packit Service 82fcde
  struct svcraw_private_s *srp = svcraw_private;
Packit Service 82fcde
Packit Service 82fcde
  if (srp == 0)
Packit Service 82fcde
    return FALSE;
Packit Service 82fcde
  return (*xdr_args) (&srp->xdr_stream, args_ptr);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static bool_t
Packit Service 82fcde
svcraw_freeargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
Packit Service 82fcde
{
Packit Service 82fcde
  struct svcraw_private_s *srp = svcraw_private;
Packit Service 82fcde
  XDR *xdrs;
Packit Service 82fcde
Packit Service 82fcde
  if (srp == 0)
Packit Service 82fcde
    return FALSE;
Packit Service 82fcde
  xdrs = &srp->xdr_stream;
Packit Service 82fcde
  xdrs->x_op = XDR_FREE;
Packit Service 82fcde
  return (*xdr_args) (xdrs, args_ptr);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static void
Packit Service 82fcde
svcraw_destroy (SVCXPRT *xprt)
Packit Service 82fcde
{
Packit Service 82fcde
}