svc_raw.c 3.9 KB

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