svc.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:12k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* svc.h, Server-side remote procedure call interface. */
  2. /* Copyright 1984-1993 Wind River Systems, Inc. */
  3. /*
  4.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  5.  * unrestricted use provided that this legend is included on all tape
  6.  * media and as a part of the software program in whole or part.  Users
  7.  * may copy or modify Sun RPC without charge, but are not authorized
  8.  * to license or distribute it to anyone else except as part of a product or
  9.  * program developed by the user.
  10.  *
  11.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  12.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  13.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  14.  *
  15.  * Sun RPC is provided with no support and without any obligation on the
  16.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  17.  * modification or enhancement.
  18.  *
  19.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  20.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  21.  * OR ANY PART THEREOF.
  22.  *
  23.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  24.  * or profits or other special, indirect and consequential damages, even if
  25.  * Sun has been advised of the possibility of such damages.
  26.  *
  27.  * Sun Microsystems, Inc.
  28.  * 2550 Garcia Avenue
  29.  * Mountain View, California  94043
  30.  */
  31. /*      @(#)svc.h 1.1 86/02/03 SMI      */
  32. /*
  33.  * svc.h, Server-side remote procedure call interface.
  34.  *
  35.  * Copyright (C) 1984, Sun Microsystems, Inc.
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01m,24feb97,bjl  moved struct xp_ops declaration outside of SVCXPRT 
  41.  to make struct xp_ops globally visible for c++
  42. 01l,15sep93,kdl  changed prototype of svcudp_create() (SPR #2427).
  43. 01k,22sep92,rrr  added support for c++
  44. 01j,26may92,rrr  the tree shuffle
  45. 01i,19nov91,rrr  shut up some ansi warnings.
  46. 01h,04oct91,rrr  passed through the ansification filter
  47.   -fixed broken prototype
  48.   -fixed #else and #endif
  49.   -changed copyright notice
  50. 01g,08may91,kdl  fixed ANSI prototype of svc_register().
  51. 01f,10jan91,shl  fixed prototype of registerrpc().
  52. 01e,25oct90,dnw  added missing definition of svc_fds.
  53. 01d,24oct90,shl  deleted redundant function declarations.
  54. 01c,05oct90,shl  added ANSI function prototypes.
  55.                  added copyright notice.
  56. 01b,26oct89,hjb  upgraded to release 4.0
  57. */
  58. #ifndef __INCsvch
  59. #define __INCsvch
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. /*
  64.  * This interface must manage two items concerning remote procedure calling:
  65.  *
  66.  * 1) An arbitrary number of transport connections upon which rpc requests
  67.  * are received.  The two most notable transports are TCP and UDP;  they are
  68.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  69.  * they in turn call xprt_register and xprt_unregister.
  70.  *
  71.  * 2) An arbitrary number of locally registered services.  Services are
  72.  * described by the following four data: program number, version number,
  73.  * "service dispatch" function, a transport handle, and a boolean that
  74.  * indicates whether or not the exported program should be registered with a
  75.  * local binder service;  if true the program's number and version and the
  76.  * port number from the transport handle are registered with the binder.
  77.  * These data are registered with the rpc svc system via svc_register.
  78.  *
  79.  * A service's dispatch function is called whenever an rpc request comes in
  80.  * on a transport.  The request's program and version numbers must match
  81.  * those of the registered service.  The dispatch function is passed two
  82.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  83.  */
  84. enum xprt_stat {
  85. XPRT_DIED,
  86. XPRT_MOREREQS,
  87. XPRT_IDLE
  88. };
  89. struct xp_ops {
  90.     bool_t (*xp_recv)();  /* receive incomming requests */
  91.     enum xprt_stat (*xp_stat)(); /* get transport status */
  92.     bool_t (*xp_getargs)(); /* get arguments */
  93.     bool_t (*xp_reply)();  /* send reply */
  94.     bool_t (*xp_freeargs)();/* free mem allocated for args */
  95.     void (*xp_destroy)(); /* destroy this struct */
  96. }; 
  97. /*
  98.  * Server side transport handle
  99.  */
  100. typedef struct {
  101. int xp_sock;
  102. u_short xp_port;  /* associated port number */
  103. struct xp_ops   *xp_ops;
  104. int xp_addrlen;  /* length of remote address */
  105. struct sockaddr_in xp_raddr;  /* remote address */
  106. struct opaque_auth xp_verf;  /* raw response verifier */
  107. caddr_t xp_p1;  /* private */
  108. caddr_t xp_p2;  /* private */
  109. } SVCXPRT;
  110. /*
  111.  *  Approved way of getting address of caller
  112.  */
  113. #define svc_getcaller(x) (&(x)->xp_raddr)
  114. /*
  115.  * Operations defined on an SVCXPRT handle
  116.  *
  117.  * SVCXPRT *xprt;
  118.  * struct rpc_msg *msg;
  119.  * xdrproc_t  xargs;
  120.  * caddr_t  argsp;
  121.  */
  122. #define SVC_RECV(xprt, msg)
  123. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  124. #define svc_recv(xprt, msg)
  125. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  126. #define SVC_STAT(xprt)
  127. (*(xprt)->xp_ops->xp_stat)(xprt)
  128. #define svc_stat(xprt)
  129. (*(xprt)->xp_ops->xp_stat)(xprt)
  130. #define SVC_GETARGS(xprt, xargs, argsp)
  131. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  132. #define svc_getargs(xprt, xargs, argsp)
  133. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  134. #define SVC_REPLY(xprt, msg)
  135. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  136. #define svc_reply(xprt, msg)
  137. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  138. #define SVC_FREEARGS(xprt, xargs, argsp)
  139. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  140. #define svc_freeargs(xprt, xargs, argsp)
  141. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  142. #define SVC_DESTROY(xprt)
  143. (*(xprt)->xp_ops->xp_destroy)(xprt)
  144. #define svc_destroy(xprt)
  145. (*(xprt)->xp_ops->xp_destroy)(xprt)
  146. /*
  147.  * Service request
  148.  */
  149. struct svc_req {
  150. u_long rq_prog; /* service program number */
  151. u_long rq_vers; /* service protocol version */
  152. u_long rq_proc; /* the desired procedure */
  153. struct opaque_auth rq_cred; /* raw creds from the wire */
  154. caddr_t rq_clntcred; /* read only cooked cred */
  155. SVCXPRT *rq_xprt; /* associated transport */
  156. };
  157. /*
  158.  * Service registration
  159.  *
  160.  * svc_register(xprt, prog, vers, dispatch, protocol)
  161.  * SVCXPRT *xprt;
  162.  * u_long prog;
  163.  * u_long vers;
  164.  * void (*dispatch)();
  165.  * int protocol;  /@ like TCP or UDP, zero means do not register @/
  166.  */
  167. /*
  168.  * Service un-registration
  169.  *
  170.  * svc_unregister(prog, vers)
  171.  * u_long prog;
  172.  * u_long vers;
  173.  */
  174. /*
  175.  * Transport registration.
  176.  *
  177.  * xprt_register(xprt)
  178.  * SVCXPRT *xprt;
  179.  */
  180. /*
  181.  * Transport un-register
  182.  *
  183.  * xprt_unregister(xprt)
  184.  * SVCXPRT *xprt;
  185.  */
  186. /*
  187.  * When the service routine is called, it must first check to see if it
  188.  * knows about the procedure;  if not, it should call svcerr_noproc
  189.  * and return.  If so, it should deserialize its arguments via
  190.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  191.  * svcerr_decode should be called followed by a return.  Successful
  192.  * decoding of the arguments should be followed the execution of the
  193.  * procedure's code and a call to svc_sendreply.
  194.  *
  195.  * Also, if the service refuses to execute the procedure due to too-
  196.  * weak authentication parameters, svcerr_weakauth should be called.
  197.  * Note: do not confuse access-control failure with weak authentication!
  198.  *
  199.  * NB: In pure implementations of rpc, the caller always waits for a reply
  200.  * msg.  This message is sent when svc_sendreply is called.
  201.  * Therefore pure service implementations should always call
  202.  * svc_sendreply even if the function logically returns void;  use
  203.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  204.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  205.  * case of a batched call, svc_sendreply should NOT be called since
  206.  * this would send a return message, which is what batching tries to avoid.
  207.  * It is the service/protocol writer's responsibility to know which calls are
  208.  * batched and which are not.  Warning: responding to batch calls may
  209.  * deadlock the caller and server processes!
  210.  */
  211. /*
  212.  * Lowest level dispatching -OR- who owns this process anyway.
  213.  * Somebody has to wait for incoming requests and then call the correct
  214.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  215.  * svc_run never returns.
  216.  * Since another (co-existant) package may wish to selectively wait for
  217.  * incoming calls or other events outside of the rpc architecture, the
  218.  * routine svc_getreq is provided.  It must be passed readfds, the
  219.  * "in-place" results of a select system call (see select, section 2).
  220.  */
  221. /*
  222.  * Global keeper of rpc service descriptors in use
  223.  * dynamic; must be inspected before each call to select
  224.  */
  225. #ifdef FD_SETSIZE
  226. extern fd_set svc_fdset;
  227. #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
  228. #else
  229. extern int svc_fds;
  230. #endif /* def FD_SETSIZE */
  231. /*
  232.  * a small program implemented by the svc_rpc implementation itself;
  233.  * also see clnt.h for protocol numbers.
  234.  */
  235. extern void rpctest_service();
  236. /*
  237.  * Socket to use on svcxxx_create call to get default socket
  238.  */
  239. #define RPC_ANYSOCK -1
  240. /*
  241.  * These are the existing service side transport implementations
  242.  */
  243. /*
  244.  * Memory based rpc for testing and timing.
  245.  */
  246. /* extern SVCXPRT *svcraw_create(); */
  247. /*
  248.  * Udp based rpc.
  249.  */
  250. /*
  251. extern SVCXPRT *svcudp_create();
  252. extern SVCXPRT *svcudp_bufcreate();
  253. */
  254. /*
  255.  * Tcp based rpc.
  256.  */
  257. /*
  258. extern SVCXPRT *svctcp_create();
  259. */
  260. /* function declarations */
  261. #if defined(__STDC__) || defined(__cplusplus)
  262. extern   void        xprt_register (SVCXPRT *xprt);
  263. extern   void        xprt_unregister (SVCXPRT *xprt);
  264. extern   bool_t       svc_register (SVCXPRT *xprt, u_long prog, u_long vers,
  265.      void (*dispatch)(), int protocol);
  266. extern   void        svc_unregister (u_long prog, u_long vers);
  267. extern   struct       svc_callout *svc_find (u_long prog, u_long vers,
  268.       struct svc_callout **prev);
  269. extern   bool_t       svc_sendreply (SVCXPRT *xprt, xdrproc_t xdr_results,
  270.       caddr_t xdr_location);
  271. extern   void        svcerr_noproc (SVCXPRT *xprt);
  272. extern   void        svcerr_decode (SVCXPRT *xprt);
  273. extern   void        svcerr_systemerr (SVCXPRT *xprt);
  274. extern   void        svcerr_auth (SVCXPRT *xprt, enum auth_stat why);
  275. extern   void        svcerr_weakauth (SVCXPRT *xprt);
  276. extern   void        svcerr_noprog (SVCXPRT *xprt);
  277. extern   void        svcerr_progvers (SVCXPRT *xprt, u_long low_vers,
  278. u_long high_vers);
  279. extern   void        svc_getreq (int rdfds);
  280. extern   void        svc_getreqset (fd_set *rdfds);
  281. extern   void        svc_run (void);
  282. extern   SVCXPRT *    svcraw_create (void);
  283. extern   int        registerrpc (int prognum, int versnum, int procnum,
  284.     char *(*progname)(), xdrproc_t inproc,
  285.     xdrproc_t outproc);
  286. extern   SVCXPRT *    svctcp_create (int sock, u_int sendsize, u_int recvsize);
  287. extern   SVCXPRT *    svcfd_create (int fd, u_int sendsize, u_int recvsize);
  288. extern   SVCXPRT *    svcudp_bufcreate (int sock, u_int sendsz, u_int recvsz);
  289. extern   SVCXPRT *    svcudp_create (int sock);
  290. extern   int        svcudp_enablecache (SVCXPRT *transp, u_long size);
  291. #else
  292. extern   void        xprt_register ();
  293. extern   void        xprt_unregister ();
  294. extern   bool_t       svc_register ();
  295. extern   void        svc_unregister ();
  296. extern   struct       svc_callout *svc_find ();
  297. extern   bool_t       svc_sendreply ();
  298. extern   void        svcerr_noproc ();
  299. extern   void        svcerr_decode ();
  300. extern   void        svcerr_systemerr ();
  301. extern   void        svcerr_auth ();
  302. extern   void        svcerr_weakauth ();
  303. extern   void        svcerr_noprog ();
  304. extern   void        svcerr_progvers ();
  305. extern   void        svc_getreq ();
  306. extern   void        svc_getreqset ();
  307. extern   void        svc_run ();
  308. extern   SVCXPRT *    svcraw_create ();
  309. extern   int        registerrpc ();
  310. extern   SVCXPRT *    svctcp_create ();
  311. extern   SVCXPRT *    svcfd_create ();
  312. extern   SVCXPRT *    svcudp_bufcreate ();
  313. extern   SVCXPRT *    svcudp_create ();
  314. extern   int        svcudp_enablecache ();
  315. #endif /* __STDC__ */
  316. #ifdef __cplusplus
  317. }
  318. #endif
  319. #endif /* __INCsvch */