本文整理汇总了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;
//.........这里部分代码省略.........
示例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))
//.........这里部分代码省略.........