⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svc.h

📁 VRTX 商用嵌入式实时操作系统
💻 H
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
*
*		Copyright (c) 1994 MICROTEC RESEARCH INCORPORATED.
*
*	All rights reserved. MICROTEC RESEARCH's source code is an unpublished
*	work and the use of a copyright notice does not imply otherwise.
*	This source code contains confidential, trade secret material of
*	MICROTEC RESEARCH. Any attempt or participation in deciphering,
*	decoding, reverse engineering or in any way altering the source code
*	is strictly prohibited, unless the prior written consent of
*	MICROTEC RESEARCH is obtained.
*
*
*	Module Name:		%M%
*
*	Identification:		%Z% %I% %M%
*
*	Date:			%G%  %U%
*
****************************************************************************
*/

/* @(#)svc.h	2.2 88/07/29 4.0 RPCSRC 1995 Microtec Research Inc.";*/
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/*
 * svc.h, Server-side remote procedure call interface.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include <ansiprot.h>

#ifndef __SVC_HEADER__
#define __SVC_HEADER__

#ifdef __cplusplus
extern "C" {
#endif

/*
 * This interface must manage two items concerning remote procedure calling:
 *
 * 1) An arbitrary number of transport connections upon which rpc requests
 * are received.  The two most notable transports are TCP and UDP;  they are
 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
 * they in turn call xprt_register and xprt_unregister.
 *
 * 2) An arbitrary number of locally registered services.  Services are
 * described by the following four data: program number, version number,
 * "service dispatch" function, a transport handle, and a boolean that
 * indicates whether or not the exported program should be registered with a
 * local binder service;  if true the program's number and version and the
 * port number from the transport handle are registered with the binder.
 * These data are registered with the rpc svc system via svc_register.
 *
 * A service's dispatch function is called whenever an rpc request comes in
 * on a transport.  The request's program and version numbers must match
 * those of the registered service.  The dispatch function is passed two
 * parameters, struct svc_req * and SVCXPRT *, defined below.
 */

enum xprt_stat {
	XPRT_DIED,
	XPRT_MOREREQS,
	XPRT_IDLE
};

/*
 * Server side transport handle
 */
typedef struct _svcxprt {
	int		xp_sock;
	u_short		xp_port;	 /* associated port number */
	struct xp_ops {
	    /* receive incomming requests */
	    bool_t	(*xp_recv) (ANSIPROT2(struct _svcxprt *,
					      struct rpc_msg *)); 
	    /* get transport status */
	    enum xprt_stat (*xp_stat) (ANSIPROT1(struct _svcxprt *));
	    /* get arguments */
	    bool_t	(*xp_getargs) (ANSIPROT3(struct _svcxprt *, xdrproc_t,
						 caddr_t)); 
	    /* send reply */
	    bool_t	(*xp_reply) (ANSIPROT2(struct _svcxprt *, struct
					       rpc_msg *)); 
	    /* free mem allocated for args */
	    bool_t	(*xp_freeargs) (ANSIPROT3(struct _svcxprt *, xdrproc_t,
						  caddr_t)); 
	    /* destroy this struct */
	    void	(*xp_destroy) (ANSIPROT1(struct _svcxprt *)); 
	} *xp_ops;
	int		xp_addrlen;	 /* length of remote address */
	struct sockaddr_in xp_raddr;	 /* remote address */
	struct opaque_auth xp_verf;	 /* raw response verifier */
	caddr_t		xp_p1;		 /* private */
	caddr_t		xp_p2;		 /* private */
} SVCXPRT;

/*
 *  Approved way of getting address of caller
 */
#define svc_getcaller(x) (&(x)->xp_raddr)

/*
 * Operations defined on an SVCXPRT handle
 *
 * SVCXPRT		*xprt;
 * struct rpc_msg	*msg;
 * xdrproc_t		 xargs;
 * caddr_t		 argsp;
 */
extern int xports_mtx_id;
extern void rpc_mutex_lock (ANSIPROT1(int));
extern void rpc_mutex_unlock (ANSIPROT1(int));

#if (defined __STDC) || defined (__cplusplus)
static bool_t svcrecv (SVCXPRT *xprt, struct rpc_msg *msg) \
{                            \
        bool_t res,(*svc_func) (ANSIPROT2(SVCXPRT *, struct rpc_msg *)); \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_recv;                \
        rpc_mutex_unlock(xports_mtx_id);                \
        res = (*svc_func)(xprt, msg);                \
        return(res);                                    \
        }
#else
static bool_t svcrecv (xprt,msg) \
SVCXPRT              *xprt;\
struct rpc_msg       *msg; \
{                            \
        bool_t res,(*svc_func) (ANSIPROT2(SVCXPRT *, struct rpc_msg *)); \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_recv;                \
        rpc_mutex_unlock(xports_mtx_id);                \
        res = (*svc_func)(xprt, msg);                \
        return(res);                                    \
}
#endif /* __STDC__ */

#define SVC_RECV(xprt, msg)                            \
	svcrecv((xprt),(msg))
#define svc_recv(xprt, msg)				\
	svcrecv((xprt),(msg))

#if (defined __STDC) || defined (__cplusplus)	     
static enum xprt_stat svcstat(SVCXPRT *xprt) \
{                            \
        enum xprt_stat res,(*svc_func) (ANSIPROT1(struct _svcxprt *));  \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_stat;               \
        rpc_mutex_unlock(xports_mtx_id);                \
        res = (*svc_func)(xprt);                \
        return(res);                                    \
        }
#else
static enum xprt_stat svcstat(xprt) \
SVCXPRT              *xprt;\
{                            \
        enum xprt_stat res,(*svc_func) (ANSIPROT1(struct _svcxprt *));  \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_stat;               \
        rpc_mutex_unlock(xports_mtx_id);                \
        res = (*svc_func)(xprt);                \
        return(res);                                    \
}
#endif /* __STDC__ */
#define SVC_STAT(xprt)					\
	svcstat(xprt)
#define svc_stat(xprt)					\
	svcstat(xprt)

#if (defined __STDC) || defined (__cplusplus)	     
static bool_t svcgetargs(SVCXPRT *xprt, xdrproc_t xargs, caddr_t argsp) \
{                            \
        bool_t res,(*svc_func) (ANSIPROT3(SVCXPRT *, xdrproc_t, caddr_t));  \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_getargs;                \
        rpc_mutex_unlock(xports_mtx_id);                \
        res = (*svc_func)(xprt,xargs,argsp);                \
        return(res);                                    \
        }
#else
static bool_t svcgetargs(xprt,xargs,argsp) \
SVCXPRT              *xprt;\
xdrproc_t             xargs;\
caddr_t               argsp;\
{                            \
        bool_t res,(*svc_func) (ANSIPROT3(SVCXPRT *, xdrproc_t, caddr_t));  \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_getargs;                \
        rpc_mutex_unlock(xports_mtx_id);                \
        res = (*svc_func)(xprt,xargs,argsp);                \
        return(res);                                    \
}
#endif /* __STDC__ */
#define SVC_GETARGS(xprt, xargs, argsp)			\
	svcgetargs((xprt),(xargs),(argsp))
#define svc_getargs(xprt, xargs, argsp)			\
	svcgetargs((xprt),(xargs),(argsp))

#if (defined __STDC) || defined (__cplusplus)
static bool_t svcreply(SVCXPRT *xprt, struct rpc_msg *msg) \
{                            \
        bool_t res,(*svc_func) (ANSIPROT2(SVCXPRT *, struct rpc_msg *)); \
        rpc_mutex_lock(xports_mtx_id);                  \
        svc_func = xprt->xp_ops->xp_reply;                \
        rpc_mutex_unlock(xports_mtx_id);                \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -