当前位置: 首页>>代码示例>>C++>>正文


C++ CTcpSocket::GetLastError方法代码示例

本文整理汇总了C++中CTcpSocket::GetLastError方法的典型用法代码示例。如果您正苦于以下问题:C++ CTcpSocket::GetLastError方法的具体用法?C++ CTcpSocket::GetLastError怎么用?C++ CTcpSocket::GetLastError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CTcpSocket的用法示例。


在下文中一共展示了CTcpSocket::GetLastError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: F1005

int F1005(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	
	*pRetCode=-1;
	ST_CPACK aPack;	
	
	CCcbTrans   CcbTran(in_pack);
	CCcbTrans *pTrans = &CcbTran;
	if(!pTrans->AssignReqHead())
	{
		strcpy(szMsg,pTrans->getErrMsg().c_str());
	    	cout<<szMsg<<endl;
		return -1;
	}	
	pTrans->prepare();
	if(!pTrans->replaceTemlateVarValue())
	{
		strcpy(szMsg,pTrans->getErrMsg().c_str());
	    	cout<<szMsg<<endl;
		return -1;
	}

	CTcpSocket  tcpSocket;
	int ret = -1;
	string bankReqData,bankRepData;

	if(!pTrans->buildBankRequestData(pTrans->getTemplateData(),bankReqData))
	{
		strcpy(szMsg,pTrans->getErrMsg().c_str());
	    	cout<<szMsg<<endl;
		return -1;
	}

	if(pTrans->debug)
		cout<<"bankReqData : "<<bankReqData<<endl;

	if(!tcpSocket.ConnectTcp((char*)pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port))
	{
		*pRetCode=9999;
		sprintf(szMsg,"连接建设银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
	    	cout<<szMsg<<endl;
		writelog(LOG_ERR,szMsg);
		return -1;
	}
	ret = tcpSocket.Send((char*)bankReqData.c_str(),bankReqData.length());
	if(ret!=bankReqData.length())
	{
		*pRetCode=9999;
		sprintf(szMsg,"发送数据到建设银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
	    	cout<<szMsg<<endl;
		writelog(LOG_ERR,szMsg);
		return -1;
	}

	CCBMSGHEAD ccbMsgHead;
	char *pccbMsgHead =(char*) &ccbMsgHead;
	ret = tcpSocket.Recv(pccbMsgHead, sizeof(ccbMsgHead), pTrans->pBank->getNCService().timeout*1000);		
	if(ret<=0)
	{
		char errBuf[256];
		*pRetCode=9999;
		tcpSocket.GetLastError(errBuf);
		sprintf(szMsg,"从建设银行IP[%s]Port[%d] 接收数据失败,Error: %s\n",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port,errBuf);
	    	cout<<szMsg<<endl;
		writelog(LOG_ERR,szMsg);
		return -1;
	}

	if(pTrans->debug)
	{
		cout<<"length: "<< ccbMsgHead.msgDataLen<<"type: " <<ccbMsgHead.commMode<<endl;
		cout<<ccbMsgHead.txCode <<" curblock : "<<ccbMsgHead.curBlock<<"totalblock : "<<ccbMsgHead.totalBlock<<endl;
	}
	int len = atoi(ccbMsgHead.msgDataLen);
	char *pRcvBuf=(char*)malloc(len+1);
	
	ret = tcpSocket.Recv(pRcvBuf, len, pTrans->pBank->getNCService().timeout*1000);		
	if(ret<=0)
	{
		*pRetCode=9999;
		sprintf(szMsg,"从建设银行IP[%s]Port[%d] 接收数据失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
	    	cout<<szMsg<<endl;
		writelog(LOG_ERR,szMsg);
		return -1;
	}
	
	tcpSocket.Close();
	pRcvBuf[len] =0;
	bankRepData = string(pRcvBuf,len);
	if(pTrans->debug)
		cout<<"报文: bankRepData:"<<bankRepData<<endl;

	free(pRcvBuf);

	string fileName;
	if(getNodeValByNodeName(bankRepData, "FileName", fileName))
	{
		string repFile = "ccbRepFile";
		fileName.erase(0,fileName.find('\\'));
		repFile += fileName;
//.........这里部分代码省略.........
开发者ID:Codiscope-Research,项目名称:ykt4sungard,代码行数:101,代码来源:F1005.cpp

示例2: F1004

int F1004(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
    int ret=0;

    *pRetCode=-1;
    ST_CPACK aPack;
    CTcpSocket  tcpSocket;
    CBcomTrans   BcomTran(in_pack);
    CTrans *pTrans = &BcomTran;
    if(!pTrans->AssignReqHead())
    {
        strcpy(szMsg,pTrans->getErrMsg().c_str());
        cout<<szMsg<<endl;
        return -1;
    }
    pTrans->prepare();

    if(!pTrans->replaceTemlateVarValue())
    {
        strcpy(szMsg,pTrans->getErrMsg().c_str());
        cout<<szMsg<<endl;
        return -1;
    }

    string signReqData;
    if(!pTrans->buildSignData(signReqData))
    {
        strcpy(szMsg,pTrans->getErrMsg().c_str());
        cout<<szMsg<<endl;
        return -1;
    }
    if(pTrans->debug)
        cout<<"signReqData: "<<signReqData.c_str()<<endl;


    if(!tcpSocket.ConnectTcp((char*)pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port))
    {
        *pRetCode=9999;
        sprintf(szMsg,"连接交通银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
        cout<<szMsg<<endl;
        writelog(LOG_ERR,szMsg);
        return -1;
    }
    ret = tcpSocket.Send((char*)signReqData.c_str(),signReqData.length());
    if(ret!=signReqData.length())
    {
        *pRetCode=9999;
        sprintf(szMsg,"发送数据到交通银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
        cout<<szMsg<<endl;
        writelog(LOG_ERR,szMsg);
        return -1;
    }

    char szBufLen[8]="";
    int timout=pTrans->pBank->getNCService().timeout*1000;
    ret = tcpSocket.Recv(szBufLen, 7, timout);
    if(ret<=0)
    {
        *pRetCode=9999;
        sprintf(szMsg,"从交通银行IP[%s]Port[%d] 接收数据失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
        cout<<szMsg<<endl;
        writelog(LOG_ERR,szMsg);
        return -1;
    }
    if(pTrans->debug)
        cout<<"报文长度 : "<<szBufLen<<endl;
    int len = atol(szBufLen+1);

    char *pRcvBuf=(char*)malloc(len+1);
    if(!pRcvBuf)
    {
        *pRetCode=9999;
        sprintf(szMsg,"从交通银行IP[%s]Port[%d] 接收数据失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
        cout<<szMsg<<endl;
        writelog(LOG_ERR,szMsg);
        free(pRcvBuf);
        return -1;
    }
    ret = tcpSocket.Recv(pRcvBuf, len, timout);
    if(ret<0)
    {
        char errBuf[256];
        *pRetCode=9999;
        tcpSocket.GetLastError(errBuf);
        sprintf(szMsg,"从交通银行IP[%s]Port[%d] 接收数据失败,errMsg:[%s]",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port,errBuf);
        cout<<szMsg<<endl;
        writelog(LOG_ERR,szMsg);
        free(pRcvBuf);
        return -1;
    }
    tcpSocket.Close();
    pRcvBuf[len] = 0;
    if(pTrans->debug)
        cout<<pRcvBuf<<endl;

    string bankVerifyData(pRcvBuf,len);
    free(pRcvBuf);

    string bankData;
    if(!pTrans->parseVerifyBankSignedData(bankVerifyData,bankData))
//.........这里部分代码省略.........
开发者ID:nykma,项目名称:ykt4sungard,代码行数:101,代码来源:F1004.cpp


注:本文中的CTcpSocket::GetLastError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。