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

📄 wtxrpc.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 3 页
字号:
    nMatchedPatterns = sscanf (rpcKey, keyPat, pSplitKey->host,					       pSplitKey->ipAddr, progNum,					       version, protocol, portNum);    /*     * The port number may not be present in the key. Lets' examine if we got     * all the elements or not.     */    if (nMatchedPatterns == nPatternsToMatch)	{    	pSplitKey->port = (unsigned short) atoi (portNum);	}    else	{	if (nMatchedPatterns == (nPatternsToMatch-1))	    {	/* port number not present. Use the portmapper */	    pSplitKey->port = 0;	/* use portmapper */	    }	else	/* something wrong in the key! */	    return (WTX_ERROR);	}    pSplitKey->progNum = atoi (progNum);    pSplitKey->version = atoi (version);    if (! strcmp (protocol, "udp"))	pSplitKey->protocol = IPPROTO_UDP;    else if (! strcmp (protocol, "tcp"))	pSplitKey->protocol = IPPROTO_TCP;    else	return (WTX_ERROR);    return (WTX_OK);    }/********************************************************************************* wtxRpcExchangeCreate - create a new exchange client using the RPC transport** This routine takes a wpwr key string and creates a new exchange client* * RETURNS: WTX_OK, or WTX_ERROR** NOMANUAL*/STATUS wtxRpcExchangeCreate    (    WTX_XID		xid,		/* Exchange handle */    const char *	key		/* Key for server to connect to */    )    {    WTX_RPC_SPLIT_KEY	split;			/* split key */    struct sockaddr_in	addr;			/* socket address */    int			rpcSock;		/* rpc socket */    CLIENT *		pClient;		/* rpc client handle */#ifdef HOST    struct hostent *	pHostEnt;		/* host entry */    char *              registryHost;           /* registry host name */#endif	/* HOST */    if (key != NULL)	{	if (wtxRpcKeySplit (key, &split) != WTX_OK)	    WTX_EXCHANGE_RETURN (xid, 				 WTX_ERR_EXCHANGE_BAD_KEY, WTX_ERROR);	}    else 	{	/*	 * NULL key => contact the registry service so fill in the split key	 * with the Tornado registry particulars 	 */#ifdef HOST	if ((registryHost = wpwrGetEnv ("WIND_REGISTRY")) == NULL)	    registryHost = "127.0.0.1";			/* its probably local */	strncpy (split.host, registryHost, sizeof (split.host));	split.host [sizeof (split.host) - 1] = '\0';#endif	split.port = REGISTRY_PORT;	/*	 * Set ipAddr to the empty string.  That will cause the address	 * lookup logic below to use gethostbyname for us.	 */	strcpy (split.ipAddr, "");	split.progNum	= WTX_SVC_BASE;	split.version	= 1;	split.protocol	= IPPROTO_TCP;	}    /*      * Get the internet address for the given host.  Parse hostname     * as host name or alternatively in the `xx.xx.xx.xx' notation.      */    memset ((void *) &addr, 0, sizeof (addr));    /*     * Get the IP address. First use the dotted decimal part of the     * split key if that is comprehensible.  Otherwise use     * gethostbyname to look up the address.  If that fails try to     * parse the hostname itself as a dotted decimal.  Otherwise     * complain.      */    if (split.ipAddr [0]	&& (int) (addr.sin_addr.s_addr = inet_addr (split.ipAddr)) != -1)	;#ifdef HOST#ifdef WIN32    else if ((addr.sin_addr.s_addr = inet_addr (split.host)) != INADDR_NONE)	;    else if ((pHostEnt = (struct hostent *)gethostbyname (split.host)) != NULL)	addr.sin_addr.s_addr = * ((u_long *) pHostEnt->h_addr_list[0]);    else 	WTX_EXCHANGE_RETURN (xid, WTX_ERR_EXCHANGE_NO_SERVER, WTX_ERROR);#else    else if ((pHostEnt = (struct hostent *)gethostbyname (split.host)) != NULL)	addr.sin_addr.s_addr = * ((u_long *) pHostEnt->h_addr_list[0]);    else if ( (int) (addr.sin_addr.s_addr = inet_addr (split.host)) == -1)	WTX_EXCHANGE_RETURN (xid, WTX_ERR_EXCHANGE_NO_SERVER, WTX_ERROR);#endif /* WIN32 */#else    else	addr.sin_addr.s_addr = syncRegistry;#endif /* HOST */try_again:    addr.sin_family	= AF_INET;    addr.sin_port = htons(split.port);	/* given by registry/portmapper */    rpcSock = RPC_ANYSOCK;		/* any old socket */        if (split.protocol == IPPROTO_TCP)	pClient = clnttcp_create (&addr, split.progNum, split.version,				  &rpcSock, 0, 0);    else	pClient = clntudp_create (&addr, split.progNum, split.version, 				  rpcDefaultUdpTimeout, &rpcSock);    /*     * If we cannot contact the registry with a well-known port, perhaps is it     * an old one. Try using the registry local portmapper.     */         if ((pClient == NULL) && (split.port != 0))	{	split.port = 0;	goto try_again;	}    if (pClient == NULL)				/* transport failed? */	WTX_EXCHANGE_RETURN (xid, WTX_ERR_EXCHANGE_NO_SERVER, WTX_ERROR);    /* Set up the authorization mechanism */#ifdef HOST#ifndef WIN32    pClient->cl_auth = authunix_create_default();#else    pClient->cl_auth = authunix_create("WIN32", wpwrGetUid(), NULL, NULL, NULL);#endif /* WIN32 */#else    /* authentication */    pClient->cl_auth = authunix_create ("", 0, 0, 0, NULL);    /* set the real value computed on host and stored on target */    pClient->cl_auth->ah_cred.oa_flavor = authCred.oa_flavor;    pClient->cl_auth->ah_cred.oa_base = authCred.oa_base;    pClient->cl_auth->ah_cred.oa_length = authCred.oa_length;#endif  /* HOST */    xid->transport = pClient;#ifndef HOST#if (CPU==SIMHPPA)    /*     *  Set RPC receive buffer for HPSIM when using SLIP.  This is needed for     *  target symbol synchronization, since the target server can send     *  messages larger than the target MTU when not communicating thru WDB.     */    {    WDB_AGENT_INFO agentInfo;    int blen;    wdbInfoGet (&agentInfo);    blen = agentInfo.mtu;    if ( blen < 1000 )			/* Must be using SLIP */	setsockopt (rpcSock, SOL_SOCKET, SO_RCVBUF, 		    (void *) &blen, sizeof (blen));    }#endif#endif    return WTX_OK;    }/********************************************************************************* wtxRpcExchangeControl - perform a miscellaneous exchange control function.** This routine performs a miscellaneous control function on the exchange * handle <xid>. ** RETURNS: WTX_OK, or WTX_ERROR.** ERRORS: WTX_ERR_EXCHANGE_INVALID_HANDLE, WTX_ERR_EXCHANGE_INVALID_ARG** NOMANUAL*/STATUS wtxRpcExchangeControl    (    WTX_XID	xid,		/* Exchange handle */    UINT32	request,	/* Exchange control request number */    void *	arg		/* Pointer to request argument */    )    {    CLIENT * pClient;    pClient = (CLIENT *) xid->transport;    switch (request) 	{	case WTX_EXCHANGE_CTL_TIMEOUT_SET:	    xid->timeout = *(UINT32 *) arg;	    break;	    	case WTX_EXCHANGE_CTL_TIMEOUT_GET:	    *(UINT32 *) arg = xid->timeout;	    break;	    	default:	    WTX_EXCHANGE_RETURN (xid, WTX_ERR_EXCHANGE_REQUEST_UNSUPPORTED, 				 WTX_ERROR);	}    return WTX_OK;    }/********************************************************************************* wxRpcDelete - delete the exchange handle and any transport connection.** This routine deletes the exchange mechanism specified by the exchange * handle <xid>. <xid> should not be used again in any further exchange* calls as the underlying transport mechanism is closed also.** RETURNS: WTX_OK, or WTX_ERROR** NOMANUAL*/STATUS wtxRpcExchangeDelete    (    WTX_XID xid			/* Exchange handle */    )    {    CLIENT *pClient;    pClient = (CLIENT *) xid->transport;    if (pClient == NULL)	/* Nothing to do */	return WTX_OK;    if (pClient->cl_auth != NULL)	auth_destroy (pClient->cl_auth);    clnt_destroy (pClient);    xid->transport = NULL;    return (WTX_OK);    }/********************************************************************************* wtxRpcExchangeFree - free a exchange call result message** This routine frees the memory allocated internally to the result message* <pMsg> used in making the exchange service call <svcNum>.** RETURNS: WTX_OK, or WTX_ERROR** NOMANUAL*/STATUS wtxRpcExchangeFree    (    WTX_XID	xid,		/* exchange handle */    WTX_REQUEST	svcNum,		/* number of server service result to free */    void *	pMsg		/* pointer to result message to free */    )    {    CLIENT * pClient;    pClient = (CLIENT *) xid->transport;    /*     * With RPC we cannot free a result after the exchange is disconnected     * because the clnt_freeres uses the XDR data which is lost on the     * clnt_destroy().      */    if (pClient == NULL)	WTX_EXCHANGE_RETURN (xid, WTX_ERR_EXCHANGE_NO_TRANSPORT, WTX_ERROR);    if (svcNum > rpcSvcTableSize || (*rpcSvcTable)[svcNum] == NULL)	WTX_EXCHANGE_RETURN (xid, WTX_ERR_EXCHANGE_REQUEST_UNSUPPORTED,			     WTX_ERROR);    clnt_freeres (pClient, (*rpcSvcTable)[svcNum]->xdrOut, pMsg);     return (WTX_OK);    }/********************************************************************************* wtxRpcExchange - do a WTX API call via the exchange mechanism** This routine performs the exchange service call <svcNum> with in parameters* pointed to by <pIn> and result (out) parameters pointed to by <pOut>. The

⌨️ 快捷键说明

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