Back to index

glibc  2.9
svc_raw.c
Go to the documentation of this file.
00001 /* @(#)svc_raw.c     2.1 88/07/29 4.0 RPCSRC */
00002 /*
00003  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00004  * unrestricted use provided that this legend is included on all tape
00005  * media and as a part of the software program in whole or part.  Users
00006  * may copy or modify Sun RPC without charge, but are not authorized
00007  * to license or distribute it to anyone else except as part of a product or
00008  * program developed by the user.
00009  *
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  *
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  *
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  *
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  *
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 #if !defined(lint) && defined(SCCSIDS)
00031 static char sccsid[] = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
00032 #endif
00033 
00034 /*
00035  * svc_raw.c,   This a toy for simple testing and timing.
00036  * Interface to create an rpc client and server in the same UNIX process.
00037  * This lets us simulate rpc and get rpc (round trip) overhead, without
00038  * any interference from the kernel.
00039  *
00040  * Copyright (C) 1984, Sun Microsystems, Inc.
00041  */
00042 
00043 #include <rpc/rpc.h>
00044 #include <rpc/svc.h>
00045 
00046 /*
00047  * This is the "network" that we will be moving data over
00048  */
00049 struct svcraw_private_s
00050   {
00051     char _raw_buf[UDPMSGSIZE];
00052     SVCXPRT server;
00053     XDR xdr_stream;
00054     char verf_body[MAX_AUTH_BYTES];
00055   };
00056 #ifdef _RPC_THREAD_SAFE_
00057 #define svcraw_private RPC_THREAD_VARIABLE(svcraw_private_s)
00058 #else
00059 static struct svcraw_private_s *svcraw_private;
00060 #endif
00061 
00062 static bool_t svcraw_recv (SVCXPRT *, struct rpc_msg *);
00063 static enum xprt_stat svcraw_stat (SVCXPRT *);
00064 static bool_t svcraw_getargs (SVCXPRT *, xdrproc_t, caddr_t);
00065 static bool_t svcraw_reply (SVCXPRT *, struct rpc_msg *);
00066 static bool_t svcraw_freeargs (SVCXPRT *, xdrproc_t, caddr_t);
00067 static void svcraw_destroy (SVCXPRT *);
00068 
00069 static const struct xp_ops server_ops =
00070 {
00071   svcraw_recv,
00072   svcraw_stat,
00073   svcraw_getargs,
00074   svcraw_reply,
00075   svcraw_freeargs,
00076   svcraw_destroy
00077 };
00078 
00079 SVCXPRT *
00080 svcraw_create (void)
00081 {
00082   struct svcraw_private_s *srp = svcraw_private;
00083 
00084   if (srp == 0)
00085     {
00086       srp = (struct svcraw_private_s *) calloc (1, sizeof (*srp));
00087       if (srp == 0)
00088        return NULL;
00089     }
00090   srp->server.xp_sock = 0;
00091   srp->server.xp_port = 0;
00092   srp->server.xp_ops = (struct xp_ops *) &server_ops;
00093   srp->server.xp_verf.oa_base = srp->verf_body;
00094   INTUSE(xdrmem_create) (&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE,
00095                       XDR_FREE);
00096   return &srp->server;
00097 }
00098 
00099 static enum xprt_stat
00100 svcraw_stat (SVCXPRT *xprt)
00101 {
00102   return XPRT_IDLE;
00103 }
00104 
00105 static bool_t
00106 svcraw_recv (xprt, msg)
00107      SVCXPRT *xprt;
00108      struct rpc_msg *msg;
00109 {
00110   struct svcraw_private_s *srp = svcraw_private;
00111   XDR *xdrs;
00112 
00113   if (srp == 0)
00114     return FALSE;
00115   xdrs = &srp->xdr_stream;
00116   xdrs->x_op = XDR_DECODE;
00117   XDR_SETPOS (xdrs, 0);
00118   if (!INTUSE(xdr_callmsg) (xdrs, msg))
00119     return FALSE;
00120   return TRUE;
00121 }
00122 
00123 static bool_t
00124 svcraw_reply (SVCXPRT *xprt, struct rpc_msg *msg)
00125 {
00126   struct svcraw_private_s *srp = svcraw_private;
00127   XDR *xdrs;
00128 
00129   if (srp == 0)
00130     return FALSE;
00131   xdrs = &srp->xdr_stream;
00132   xdrs->x_op = XDR_ENCODE;
00133   XDR_SETPOS (xdrs, 0);
00134   if (!INTUSE(xdr_replymsg) (xdrs, msg))
00135     return FALSE;
00136   (void) XDR_GETPOS (xdrs); /* called just for overhead */
00137   return TRUE;
00138 }
00139 
00140 static bool_t
00141 svcraw_getargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
00142 {
00143   struct svcraw_private_s *srp = svcraw_private;
00144 
00145   if (srp == 0)
00146     return FALSE;
00147   return (*xdr_args) (&srp->xdr_stream, args_ptr);
00148 }
00149 
00150 static bool_t
00151 svcraw_freeargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
00152 {
00153   struct svcraw_private_s *srp = svcraw_private;
00154   XDR *xdrs;
00155 
00156   if (srp == 0)
00157     return FALSE;
00158   xdrs = &srp->xdr_stream;
00159   xdrs->x_op = XDR_FREE;
00160   return (*xdr_args) (xdrs, args_ptr);
00161 }
00162 
00163 static void
00164 svcraw_destroy (SVCXPRT *xprt)
00165 {
00166 }