本文整理汇总了C++中TIniFile::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ TIniFile::Open方法的具体用法?C++ TIniFile::Open怎么用?C++ TIniFile::Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIniFile
的用法示例。
在下文中一共展示了TIniFile::Open方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Msclient
void* Msclient(void*)
{
TIniFile tf;
char tmp[256];
if (!tf.Open(INI_FILE_NAME))
{
printf("can not find\n");
exit(-1000);
}
int marketnum = tf.ReadInt("COMMON","MARKETDATANUM",1);
int i = 0;
for(;i<marketnum;i++)
{
sprintf(tmp,"MARKETDATA%d",i+1);
CUstpMs ustpMs;
ustpMs.InitInstance(tmp,INI_FILE_NAME,&tradepanel);
}
while(false)
{
SLEEP_SECONDS(5000);
}
return 0;
}
示例2: ReadIni
bool ReadIni(char *inifile)
{
TIniFile tf;
CSList tmpstr;
char szBuf[256];
g_LogFile.Open("bulog"); // 用程序的进程号作为各个BU日志文件存放目录
memset(&g_BUnit,0,sizeof(g_BUnit));
printf("Begin to read ini-file:%s...\n",inifile);
if (!tf.Open(inifile))
{
sprintf(szBuf,"不能打开配置文件<%s>\n",inifile);
//DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
g_LogFile.RemoveOverdueLogFile(tf.ReadInt("COMMON","LOGOVERDUE",10));
//g_BUnit.iBUnitGourpID = tf.ReadInt("COMMON","GID",1);
tf.ReadString("COMMON","GID","",g_BUnit.szBUGroupID,sizeof(g_BUnit.szBUGroupID)-1);
tf.ReadString("BCC","BCCSVR","127.0.0.1:6666",szBuf,sizeof(szBuf)-1);
if (!tmpstr.FillStrings(szBuf,':') || tmpstr.GetCount()<2)
{
sprintf(szBuf,"配置文件<%s>的配置项[BCC] BCCSVR=???? 错误! 格式为:BCCSVR=xxx.xxx.xxx.xxx:port\n",inifile);
//DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
strncpy(g_BUnit.szSvrIP,tmpstr.GetAt(0),sizeof(g_BUnit.szSvrIP)-1);
g_BUnit.iSvrPort = atoi(tmpstr.GetAt(1));
g_BUnit.iHBInterval = tf.ReadInt("BCC","HEARTBEAT",5000);
if (g_BUnit.iHBInterval<100)
g_BUnit.iHBInterval = 100;
tf.Close();
return(true);
}
示例3: ReadIni_bank
int ReadIni_bank(ST_BANK_CONFIG *p_bankini)
{
TIniFile tf;
ST_BANK_CONFIG t_bank;
char szBuf[256];
char bank_unit[10]="";
char * pch;
int j=0;
memset(&t_bank,0,sizeof t_bank);
if (!tf.Open(TRANS_INI_FILE))
{
writelog(LOG_ERR,"Cann't open ini file,file's name=[%s]",TRANS_INI_FILE);
return -1;
}
t_bank.BankCount=tf.ReadInt("COMMON","BANK_UNIT",1);
t_bank.BCC_BASEFUNCNO=tf.ReadInt("COMMON","BCC_BASEFUNCNO",9000);
t_bank.DRTP_BRANCH=tf.ReadInt("COMMON","DRTP_BRANCH",7000);
t_bank.TIMEOUT=tf.ReadInt("COMMON","TIMEOUT",5);
t_bank.DRTP_PORT=tf.ReadInt("COMMON","DRTP_PORT",4000);
tf.ReadString("COMMON","DRTP_IP","127.0.0.1",t_bank.DRTP_IP,sizeof(t_bank.DRTP_IP)-1);
tf.ReadString("COMMON","COMPACC_TIME","06",t_bank.COMPACC_TIME,sizeof(t_bank.COMPACC_TIME)-1);
t_bank.AUTH_MODE=tf.ReadInt("COMMON","AUTH_MODE",1);
t_bank.LOGIN_MODE=tf.ReadInt("COMMON","LOGIN_MODE",1);
t_bank.LOG_MODE=tf.ReadInt("COMMON","LOG_MODE",1);
tf.ReadString("COMMON","SERV_TIME","010000-235959",t_bank.SERV_TIME,sizeof(t_bank.SERV_TIME)-1);
t_bank.trans_money=tf.ReadInt("COMMON","TRANS_MONEY",100000);
for(int i=0;i<t_bank.BankCount;i++)
{
j=0;
sprintf(bank_unit,"BANK%d",i+1);
tf.ReadString(bank_unit,"BANK_IP","26.136.2.9",t_bank.BankUnit[i].szBankIP,sizeof(t_bank.BankUnit[i].szBankIP)-1);
t_bank.BankUnit[i].iBankID= tf.ReadInt(bank_unit,"BANK_ID",1);
t_bank.BankUnit[i].iBankPort= tf.ReadInt(bank_unit,"BANK_PORT",5301);
t_bank.BankUnit[i].iBankTimeout= tf.ReadInt(bank_unit,"BANK_DELAY_TIME",5000);
t_bank.BankUnit[i].iAuthMode= tf.ReadInt(bank_unit,"AUTH_MODE",1);
t_bank.BankUnit[i].compare_flag= tf.ReadInt(bank_unit,"COMPARE_FLAG",1);
t_bank.BankUnit[i].sendcompreq_flag= tf.ReadInt(bank_unit,"SENDCOMPREQ_FLAG",0);
t_bank.BankUnit[i].compare_count= tf.ReadInt(bank_unit,"COMPARE_COUNT",0);
tf.ReadString(bank_unit,"BANK_ACCOUNT_NO","2011",t_bank.BankUnit[i].szBankAccountNO,sizeof(t_bank.BankUnit[i].szBankAccountNO)-1); // 如果是多家银行, 此处需要填写一卡通的银行账户
tf.ReadString(bank_unit,"BANK_CARD_RANGE","",szBuf,sizeof(szBuf)-1);
tf.ReadString(bank_unit,"COMPARE_TIME","06",t_bank.BankUnit[i].compare_time,sizeof(t_bank.BankUnit[i].compare_time) - 1);
tf.ReadString(bank_unit,"SENDCOMPREQ_TIME","05",t_bank.BankUnit[i].sendcompreq_time,sizeof(t_bank.BankUnit[i].sendcompreq_time) - 1);
tf.ReadString(bank_unit,"COMP_FILE_PATH","/home",t_bank.BankUnit[i].comp_file_path,sizeof(t_bank.BankUnit[i].comp_file_path) - 1);
//writelog(LOG_INFO,"COMP_FILE_PATH=[%s], BANK_CARD_RANGE=[%s], BANK_ACCOUNT_NO=[%s]", t_bank.BankUnit[i].comp_file_path, szBuf, t_bank.BankUnit[i].szBankAccountNO);
pch = strtok (szBuf,",");
while (pch != NULL)
{
des2src(t_bank.BankUnit[i].szBankCardRange[j], pch);
pch = strtok (NULL, ",");
//writelog(LOG_INFO,"BANKID=[%d], BANKCARDRAGNT=[%s], i=[%d], j=[%d]", t_bank.BankUnit[i].iBankID, t_bank.BankUnit[i].szBankCardRange[j], i, j);
j++;
if(j>=MAX_RANGE)
break;
}
}
memcpy(p_bankini,&t_bank,sizeof(t_bank));
tf.Close();
return 0;
}
示例4: ReadIni_bank
int ReadIni_bank(ST_BANK_CONFIG *p_bankini)
{
TIniFile tf;
ST_BANK_CONFIG t_bank;
char szBuf[256];
char bank_unit[10]="";
char * pch;
int j=0;
memset(&t_bank,0,sizeof t_bank);
if (!tf.Open(TRANS_INI_FILE))
{
writelog(LOG_ERR,"Cann't open ini file,file's name=[%s]",TRANS_INI_FILE);
return -1;
}
t_bank.BankCount=tf.ReadInt("COMMON","BANK_UNIT",1);
t_bank.BCC_BASEFUNCNO=tf.ReadInt("COMMON","BCC_BASEFUNCNO",9000);
t_bank.DRTP_BRANCH=tf.ReadInt("COMMON","DRTP_BRANCH",7000);
t_bank.TIMEOUT=tf.ReadInt("COMMON","TIMEOUT",5);
t_bank.DRTP_PORT=tf.ReadInt("COMMON","DRTP_PORT",4000);
tf.ReadString("COMMON","DRTP_IP","127.0.0.1",t_bank.DRTP_IP,sizeof(t_bank.DRTP_IP)-1);
tf.ReadString("COMMON","COMPACC_TIME","06",t_bank.COMPACC_TIME,sizeof(t_bank.COMPACC_TIME)-1);
t_bank.AUTH_MODE=tf.ReadInt("COMMON","AUTH_MODE",1);
t_bank.LOGIN_MODE=tf.ReadInt("COMMON","LOGIN_MODE",1);
t_bank.LOG_MODE=tf.ReadInt("COMMON","LOG_MODE",1);
tf.ReadString("COMMON","SERV_TIME","060000-235959",t_bank.SERV_TIME,sizeof(t_bank.SERV_TIME)-1);
for(int i=0;i<t_bank.BankCount;i++)
{
j=0;
sprintf(bank_unit,"BANK%d",i+1);
tf.ReadString(bank_unit,"BANK_IP","26.136.2.9",t_bank.BankUnit[i].szBankIP,sizeof(t_bank.BankUnit[i].szBankIP)-1);
t_bank.BankUnit[i].iBankID= tf.ReadInt(bank_unit,"BANK_ID",1);
t_bank.BankUnit[i].iBankPort= tf.ReadInt(bank_unit,"BANK_PORT",5301);
t_bank.BankUnit[i].iBankTimeout= tf.ReadInt(bank_unit,"BANK_DELAY_TIME",5000);
t_bank.BankUnit[i].iAuthMode= tf.ReadInt(bank_unit,"AUTH_MODE",1);
tf.ReadString(bank_unit,"BANK_ACCOUNT_NO","2011",t_bank.BankUnit[i].szBankAccountNO,sizeof(t_bank.BankUnit[i].szBankAccountNO)-1);
tf.ReadString(bank_unit,"BANK_CARD_RANGE","",szBuf,sizeof(szBuf)-1);
pch = strtok (szBuf,",");
while (pch != NULL)
{
des2src(t_bank.BankUnit[i].szBankCardRange[j], pch);
pch = strtok (NULL, ",");
j++;
if(j>=MAX_RANGE)
break;
}
}
memcpy(p_bankini,&t_bank,sizeof(t_bank));
tf.Close();
return 0;
}
示例5: ReadIni
bool ReadIni(char *inifile)
{
TIniFile tf;
CSList tmpstr;
char szBuf[256];
g_LogFile.Open("bulog"); // 用程序的进程号作为各个BU日志文件存放目录
memset(&g_BUnit,0,sizeof(g_BUnit));
printf("Begin to read ini-file:%s...\n",inifile);
if (!tf.Open(inifile))
{
sprintf(szBuf,"不能打开配置文件<%s>\n",inifile);
DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
g_LogFile.RemoveOverdueLogFile(tf.ReadInt("COMMON","LOGOVERDUE",10));
//g_BUnit.iBUnitGourpID = tf.ReadInt("COMMON","GID",1);
tf.ReadString("COMMON","GID","",g_BUnit.szBUGroupID,sizeof(g_BUnit.szBUGroupID)-1);
tf.ReadString("BCC","BCCSVR","127.0.0.1:6666",szBuf,sizeof(szBuf)-1);
if (!tmpstr.FillStrings(szBuf,':') || tmpstr.GetCount()<2)
{
sprintf(szBuf,"配置文件<%s>的配置项[BCC] BCCSVR=???? 错误! 格式为:BCCSVR=xxx.xxx.xxx.xxx:port\n",inifile);
DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
strncpy(g_BUnit.szSvrIP,tmpstr.GetAt(0),sizeof(g_BUnit.szSvrIP)-1);
g_BUnit.iSvrPort = atoi(tmpstr.GetAt(1));
g_BUnit.iHBInterval = tf.ReadInt("BCC","HEARTBEAT",5000);
if (g_BUnit.iHBInterval<100)
g_BUnit.iHBInterval = 100;
memset(szBuf,0,sizeof szBuf);
// TODO : 加密机配置
char remoteip[128]={0};
int remoteport=0;
tf.ReadString("ENCSVR","ip","",remoteip,sizeof(remoteip)-1);
BKConfiguration::instance()->save_para("encsvr.remoteip",remoteip);
remoteport = tf.ReadInt("ENCSVR","port",0);
BKConfiguration::instance()->save_int_para("encsvr.remoteport",remoteport);
int mainfunc = tf.ReadInt("ENCSVR","mainfunc",0);
BKConfiguration::instance()->save_int_para("encsvr.mainfunc",mainfunc);
int drtpno = tf.ReadInt("ENCSVR","drtpno",0);
BKConfiguration::instance()->save_int_para("encsvr.drtpno",drtpno);
tf.Close();
return(true);
}
示例6: ReadIni
bool ReadIni(char *inifile)
{
TIniFile tf;
CSList tmpstr;
char szBuf[256];
g_LogFile.Open("bulog"); // 用程序的进程号作为各个BU日志文件存放目录
memset(&g_BUnit,0,sizeof(g_BUnit));
printf("Begin to read ini-file:%s...\n",inifile);
if (!tf.Open(inifile))
{
sprintf(szBuf,"不能打开配置文件<%s>\n",inifile);
DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
g_LogFile.RemoveOverdueLogFile(tf.ReadInt("COMMON","LOGOVERDUE",10));
//g_BUnit.iBUnitGourpID = tf.ReadInt("COMMON","GID",1);
tf.ReadString("COMMON","GID","",g_BUnit.szBUGroupID,sizeof(g_BUnit.szBUGroupID)-1);
tf.ReadString("BCC","BCCSVR","127.0.0.1:6666",szBuf,sizeof(szBuf)-1);
if (!tmpstr.FillStrings(szBuf,':') || tmpstr.GetCount()<2)
{
sprintf(szBuf,"配置文件<%s>的配置项[BCC] BCCSVR=???? 错误! 格式为:BCCSVR=xxx.xxx.xxx.xxx:port\n",inifile);
DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
strncpy(g_BUnit.szSvrIP,tmpstr.GetAt(0),sizeof(g_BUnit.szSvrIP)-1);
g_BUnit.iSvrPort = atoi(tmpstr.GetAt(1));
g_BUnit.iHBInterval = tf.ReadInt("BCC","HEARTBEAT",5000);
if (g_BUnit.iHBInterval<100)
g_BUnit.iHBInterval = 100;
g_ini_para.flash_dealy = tf.ReadInt("TIME", "INIT_DELAY", 60);
g_ini_para.dynamic_load_flag = tf.ReadInt("DLLFLAG", "DYNAMIC_LOAD_FLAG", 0);
g_ini_para.sysjones_func = tf.ReadInt("DLLFLAG", "SYNJONES_FUNC", 0);
tf.ReadString("DLLFLAG", "CARDDLL", "", g_ini_para.third_part_dll_name, sizeof(g_ini_para.third_part_dll_name) - 1);
g_ini_para.port = tf.ReadInt("THIRD_ACCOUNT", "PORT", 0);
tf.ReadString("THIRD_ACCOUNT", "USER_ID", "", g_ini_para.user_id, sizeof(g_ini_para.user_id) - 1);
tf.ReadString("THIRD_ACCOUNT", "USER_PWD", "", g_ini_para.encrypt_pwd, sizeof(g_ini_para.encrypt_pwd) - 1);
tf.ReadString("THIRD_ACCOUNT", "IP", "", g_ini_para.ip, sizeof(g_ini_para.ip) - 1);
tf.ReadString("DLLFLAG", "DESDLL", "", g_ini_para.des_dll_name, sizeof(g_ini_para.des_dll_name) - 1);
g_ini_para.debug_log = tf.ReadInt("THIRD_ACCOUNT", "DEBUG_LOG", 0);
g_ini_para.des_flag = tf.ReadInt("DLLFLAG", "DESDLL_FLAG", 0);
tf.Close();
return(true);
}
示例7: ReadIni1
bool ReadIni1(char *inifile)
{
TIniFile tf;
printf("Begin to read ini-file:%s...\n",inifile);
if (!tf.Open(inifile))
return false;
g_mainsvr_func = tf.ReadInt("GDCT", "GDCT_MAIN_FUNC", 0);
g_mainsvr_drtpno = tf.ReadInt("GDCT", "GDCT_MAIN_DRTPNO", 0);
/*
tf.ReadString("GDCT", "GDCT_PSWD", "",g_gdct_pswd, sizeof(g_gdct_pswd));
tf.ReadString("GDCT", "GDCT_PHONE_NUM", "",g_gdct_phone_num, sizeof(g_gdct_phone_num));
g_timeout = tf.ReadInt("GDCT","GDCT_TIMEOUT",1000);
*/
tf.Close();
return(true);
}
示例8: ReadIni
bool ReadIni(char *inifile)
{
TIniFile tf;
CSList tmpstr;
char szBuf[256];
memset(&g_BUnit,0,sizeof(g_BUnit));
printf("Begin to read ini-file:%s...\n",inifile);
if (!tf.Open(inifile))
{
sprintf(szBuf,"不能打开配置文件<%s>\n",inifile);
DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
g_LogFile.RemoveOverdueLogFile(tf.ReadInt("COMMON","LOGOVERDUE",10));
//g_BUnit.iBUnitGourpID = tf.ReadInt("COMMON","GID",1);
tf.ReadString("COMMON","GID","",g_BUnit.szBUGroupID,sizeof(g_BUnit.szBUGroupID)-1);
tf.ReadString("BCC","BCCSVR","127.0.0.1:6666",szBuf,sizeof(szBuf)-1);
if (!tmpstr.FillStrings(szBuf,':') || tmpstr.GetCount()<2)
{
sprintf(szBuf,"配置文件<%s>的配置项[BCC] BCCSVR=???? 错误! 格式为:BCCSVR=xxx.xxx.xxx.xxx:port\n",inifile);
DEBUG_RUNTIME_MSGOUT(szBuf);
exit(-1000);
}
strncpy(g_BUnit.szSvrIP,tmpstr.GetAt(0),sizeof(g_BUnit.szSvrIP)-1);
g_BUnit.iSvrPort = atoi(tmpstr.GetAt(1));
g_BUnit.iHBInterval = tf.ReadInt("BCC","HEARTBEAT",5000);
if (g_BUnit.iHBInterval<100)
g_BUnit.iHBInterval = 100;
tf.ReadString("DB2SVR","NAME","gmserver",g_BUnit.m_SqlDB.szServer,sizeof(g_BUnit.m_SqlDB.szServer)-1);
tmpstr.trim(g_BUnit.m_SqlDB.szServer);
tf.ReadString("DB2SVR","DATABASE","gmdata",g_BUnit.m_SqlDB.szDatabase,sizeof(g_BUnit.m_SqlDB.szDatabase)-1);
tmpstr.trim(g_BUnit.m_SqlDB.szDatabase);
tf.ReadString("DB2SVR","LOGIN","sa",g_BUnit.m_SqlDB.szLogin,sizeof(g_BUnit.m_SqlDB.szLogin)-1);
tmpstr.trim(g_BUnit.m_SqlDB.szLogin);
tf.ReadString("DB2SVR","PASSWORD","",g_BUnit.m_SqlDB.szPassword,sizeof(g_BUnit.m_SqlDB.szPassword)-1);
tmpstr.trim(g_BUnit.m_SqlDB.szPassword);
tf.Close();
return(true);
}
示例9: ReadIni
bool ReadIni(char *inifile)
{
TIniFile tf;
char szBuf[256];
memset(&g_BUnit,0,sizeof(g_BUnit));
if (!tf.Open(inifile))
{
writelog(LOG_ERR,"不能打开配置文件<%s>\n",inifile);
return false;
}
tf.ReadString("DB","DB_NAME","test",g_BUnit.m_SqlDB.szDatabase,sizeof(g_BUnit.m_SqlDB.szDatabase)-1);
tf.ReadString("DB","DB_USER","db2inst4",g_BUnit.m_SqlDB.szLogin,sizeof(g_BUnit.m_SqlDB.szLogin)-1);
tf.ReadString("DB","DB_PASSWORD","db2inst4",g_BUnit.m_SqlDB.szPassword,sizeof(g_BUnit.m_SqlDB.szPassword)-1);
tf.Close();
return(true);
}
示例10: ReadIni
bool ReadIni(char *inifile)
{
TIniFile tf;
char szBuf[256];
memset(&g_para,0,sizeof(g_para));
printf("Begin to read ini-file:%s...\n",inifile);
if (!tf.Open(inifile))
{
sprintf(szBuf,"不能打开配置文件<%s>\n",inifile);
return false;
}
tf.ReadString("DRTP","drtp_ip","127.0.0.1",g_para.drtp_ip,sizeof(g_para.drtp_ip)-1);
g_para.drtp_port = tf.ReadInt("DRTP","drtp_port",4000);
g_para.main_funcno = tf.ReadInt("DRTP","main_func",9000);
g_para.drtp_timeout = tf.ReadInt("DRTP","time_out",5000);
g_para.bank_lisnport = tf.ReadInt("BANK","listen_port",4001);
g_para.bank_timeout = tf.ReadInt("DRTP","time_out",3000);
tf.Close();
return true;
}
示例11: main
int main()
{
TIniFile tf;
char tmp[256];
if (!tf.Open(INI_FILE_NAME))
{
printf("不能打开配置文件\n");
exit(-1000);
}
int marketnum = tf.ReadInt("COMMON","MARKETDATANUM",1);
int i = 0;
for(;i<marketnum;i++)
{
sprintf(tmp,"MARKETDATA%d",i+1);
CUstpMs ustpMs;
ustpMs.InitInstance(tmp,INI_FILE_NAME);
}
while(true)
{
SLEEP_SECONDS(5000);
}
return 0;
}
示例12: send_to_and_recv_from_bank
int send_to_and_recv_from_bank(char* pSend, int send_len,char* pRecv,int recv_len,int delay_time)
{
struct SockNode SockNode;
char bank_ip[20]="";
int bank_port=0;
//int delay_time=0;
int ret=0;
TIniFile tf;
if (!tf.Open(TRANS_INI_FILE))
{
writelog(LOG_ERR,"Cann't open ini file,file=[%s]\n",TRANS_INI_FILE);
return E_TRANS_UNKNOW_ERROR;
}
tf.ReadString("BANK", "BANK_IP", "127.0.0.1", bank_ip,sizeof(bank_ip));
bank_port=tf.ReadInt("BANK", "BANK_PORT",3501);
if(0==delay_time) delay_time=tf.ReadInt("BANK", "BANK_DELAY_TIME", 3000);
tf.Close();
#ifdef DEBUG
//printf("BANK_IP=[%s],BANK_PORT[%d],DELAY_TIME[%d]\n",bank_ip,bank_port,delay_time);
#endif
//连接银行
ret=SockNode.hSock.ConnectTcp(bank_ip, bank_port,30);
if(!ret)
{
writelog(LOG_ERR,"Connect to bank error,error code is [%d],bank_ip[%s],port[%d] ",ret,bank_ip,bank_port);
return E_TRANS_BANK_NETERR;
}
//发送数据到银行
ret=SockNode.hSock.Send(pSend, send_len);
if (ret<0)
{
// 发送时,端口有问题,包括被关闭
writelog(LOG_ERR,"Send to bank error,ret = %ret, error code is [%d] ",ret, errno);
return E_TRANS_BANK_NETERR;
}
else if (0==ret)
{
// 不应该出现这种情况
writelog(LOG_ERR,"Send to bank error,CTcpSocket.Send should not return this error,error code is[%d]!\n",errno);
return E_TRANS_BANK_NETERR;
}
system("sleep 1");
//接收银行返回信息
ret= SockNode.hSock.Recv(pRecv,recv_len,delay_time);
if (ret!=recv_len)
{
writelog(LOG_ERR,"Receive from bank error,ret= %ret, error code is [%d] ",ret, errno);
return E_TRANS_BANK_NOANSWER; // 接收时候出错,或超时
}
SockNode.hSock.Close();
return 0;
}
示例13: send_to_and_recv_from_bank_of_boc
int send_to_and_recv_from_bank_of_boc(char* pSend, int send_len,char* pRecv,int *recv_len,int max_recv_len,int delay_time)
{
struct SockNode SockNode,SockNode_rsp;
CTcpSocket sock;
char bank_ip[20]="";
int bank_port=0;
int bank_port_rsp=0;
//int delay_time=0;
int ret=0;
char temp[5]="";
int length=0;
TIniFile tf;
if (!tf.Open(TRANS_INI_FILE))
{
writelog(LOG_ERR,"Cann't open ini file,file=[%s]\n",TRANS_INI_FILE);
return E_TRANS_UNKNOW_ERROR;
}
tf.ReadString("BANK", "BANK_IP", "127.0.0.1", bank_ip,sizeof(bank_ip));
bank_port=tf.ReadInt("BANK", "BANK_PORT",9001);
bank_port_rsp=tf.ReadInt("BANK", "BANK_PORT_RSP",9002);
if(0==delay_time) delay_time=tf.ReadInt("BANK", "BANK_DELAY_TIME", 3000);
tf.Close();
#ifdef DEBUG
//printf("BANK_IP=[%s],BANK_PORT[%d],DELAY_TIME[%d]\n",bank_ip,bank_port,delay_time);
#endif
writelog(LOG_DEBUG,"connect to bank [%s][%d][%d]",bank_ip,bank_port,bank_port_rsp);
//连接银行
ret=SockNode.hSock.ConnectTcp(bank_ip, bank_port,5);
if(!ret)
{
writelog(LOG_ERR,"Connect to bank error,error code is [%d],bank_ip[%s],port[%d] ",ret,bank_ip,bank_port);
return E_TRANS_BANK_NETERR;
}
//发送数据到银行
ret=SockNode.hSock.Send(pSend, send_len);
if (ret<0)
{
// 发送时,端口有问题,包括被关闭
writelog(LOG_ERR,"Send to bank error,ret = %ret, error code is [%d] ",ret, errno);
return E_TRANS_BANK_NETERR;
}
else if (0==ret)
{
// 不应该出现这种情况
writelog(LOG_ERR,"Send to bank error,CTcpSocket.Send should not return this error,error code is[%d]!\n",errno);
return E_TRANS_BANK_NETERR;
}
writelog(LOG_DEBUG,"send to bank success, waiting for responsing!!");
sleep(1);
if(!sock.Create())
{
writelog(LOG_ERR,"sock.Create error!\n");
return E_TRANS_BANK_NETERR;
}
if(!sock.Listen(bank_port_rsp))
{
writelog(LOG_ERR,"sock.Listen error![%d]",errno);
return E_TRANS_BANK_NETERR;
}
CTcpSocket rcv_sock;
if(sock.Accept(rcv_sock))
{
int rcvlen = rcv_sock.Recv(pRecv,max_recv_len,delay_time);
if(rcvlen < 0)
{
writelog(LOG_ERR,"sock.Recv error![%d][%d]\n",rcvlen,errno);
return E_TRANS_BANK_NOANSWER;
}
writelog(LOG_DEBUG,"recv length[%d]",rcvlen);
*recv_len=rcvlen;
return 0;
}
return E_TRANS_BANK_NOANSWER;
/*
ret=SockNode_rsp.hSock.Listen(bank_port_rsp);
if(!ret)
{
char msg[256]="";
SockNode_rsp.hSock.GetLastError(msg);
writelog(LOG_ERR,"Listen bank error,error code is[%d],msg=[%s]!\n",ret,msg);
return E_TRANS_BANK_NETERR;
}
CTcpSocket rcv_sock;
ret=SockNode_rsp.hSock.Accept(rcv_sock);
if(ret)
{
int rcvlen = SockNode.hSock.Recv(pRecv,max_recv_len,delay_time);
if(rcvlen < 0)
{
char msg[256]="";
//.........这里部分代码省略.........
示例14: InitInstance
bool CUserApi::InitInstance(char *number, char *inifile)
{
char tmp[200];
strcpy(m_number,number);
TIniFile tf;
if (!tf.Open(inifile))
{
printf("不能打开配置文件\n");
exit(-1000);
}
// //初始化行情信息
// // 产生一个CFfexFtdcMduserApi实例
// pUserApi = CUstpFtdcMduserApi::CreateFtdcMduserApi("");
// // 产生一个事件处理的实例
// sh = new CUserSpi(pUserApi);
// // 注册一事件处理的实例
// pUserApi->RegisterSpi(sh);
// 注册需要的深度行情主题
/// USTP_TERT_RESTART:从本交易日开始重传
/// USTP_TERT_RESUME:从上次收到的续传
/// USTP_TERT_QUICK:先传送当前行情快照,再传送登录后市场行情的内容
Api->RegisterSpi(Spi);
int topicid = tf.ReadInt(m_number,"Topic",100);
int tert = tf.ReadInt(m_number,"TERT",0);
switch(tert)
{
case 0:
{
Api->SubscribeMarketDataTopic(topicid, USTP_TERT_RESTART);
break;
}
case 1:
{
Api->SubscribeMarketDataTopic(topicid, USTP_TERT_RESUME);
break;
}
case 2:
{
Api->SubscribeMarketDataTopic(topicid, USTP_TERT_QUICK);
break;
}
default:
{
qDebug()<<"配置 TERT 值不对! \n";
exit(-1);
}
}
// 设置行情发布服务器的地址
tf.ReadString(m_number,"MDUserFront","",tmp,sizeof(tmp)-1);
mytrim(tmp);
Api->RegisterFront(tmp);
// 使客户端开始与行情发布服务器建立连接
int a=0;
int b=0;
printf(Api->GetVersion(a,b));
Api->SetHeartbeatTimeout(300);
Api->Init();
Api_Thread->start();
return true;
}