📄 dnsentqcheck.cpp
字号:
/**********************************************************************
FileName : DnSentQCheck.cpp
Description : 下端已发送队列检查模块
Version : 1.0
Date : 2003年9月19日
Author : 刘荣辉
Other : 确定是否重发
***********************************************************************/
#include "DnNode.h"
int CDnNode::DnSentQCheck(DB_MySQL *MyDB ,int Relay_Interval)
{
int i;
int UnitNum;
char sSysEvent[SYS_EVENT_LEN];
struct tm *tmptime;
time_t nowtime;
int DelNum;
unsigned int PackSeq;
int QSize;
QSize = SentQ.GetSize(); //获得当前的队列大小
SendQUnit *Units=(SendQUnit *)malloc(QSize * sizeof(SendQUnit));
UnitNum = SentQ.GetAllNode(Units, QSize); //获取所有队列单元
#ifdef DEBUG
//printf("\n DnSentQCheck: UnitNum=[%d] \n",UnitNum);
#endif
for(i=0;i<UnitNum;i++) //检查各单元,确定是否重发
{
if(ToExit) //系统收到退出命令后,3秒钟内没收到应答包则将请求包进行超时处理
Units[i].SendTime = Units[i].SendTime - CMPP_SEND_TIMEOUT +3;
time(&nowtime);
if( nowtime >= Units[i].SendTime) //等待时间已到的数据包
{
//从已发送队列中删除
PackSeq = ntohl(*(unsigned int *)(Units[i].Pack + 8));
#ifdef DEBUG
printf("\n DnSentQCheck: Sequence=[%d],SendTime=[%d],nowtime=[%d],iResent=[%d]\n",PackSeq,(int)Units[i].SendTime,(int)nowtime,Units[i].iResent);
#endif
DelNum = SentQ.Delete(PackSeq);
if(DelNum!=1)
{
sprintf(sSysEvent,"Warning: %d Units[SeqId=%d] are deleted from SentQ of DnNode[%s]!",DelNum,PackSeq,ServiceCode);
WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG);
}
else
{
#ifdef DEBUG
printf("\n DnSentQCheck: A Unit[%d] is deleted from SentQ.\n",PackSeq);
#endif
}
if(Units[i].iResent || ToExit) //可重发的请求包,或者发送失败的应答包
{
//转存到待发送队列
if(SendQ->Put(Units[i])==false)
{
sprintf(sSysEvent,"Warning: SendQ of DnNode[%s] is full! Cann't transmit a pack[%d] from SentQ.",ServiceCode,PackSeq);
WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG);
}
else
{
#ifdef DEBUG
printf("\n DnSentQCheck: A CMPP_Pack[%d] of DnNode[%s] is transmited from SentQ to SendQ.\n",PackSeq,ServiceCode);
#endif
}
}
else //最大发送次数已满,仍未等到应答的请求包
{
if(ntohl(*(int *)Units[i].Pack) == CMPP_DELIVER) //对于CMPP_Deliver包,要缓存到数据库
{
//写入上行转发记录缓存表,以后再发
Cmpp_MO_Log MoLog;
tmptime = localtime(&Units[i].SrcRecvTime);
sprintf( MoLog.SrcRecvTime, "%d%02d%02d%02d%02d%02d",
tmptime->tm_year + 1900,
tmptime->tm_mon + 1,
tmptime->tm_mday,
tmptime->tm_hour,
tmptime->tm_min,
tmptime->tm_sec);
MoLog.SrcNode = Units[i].SrcNode;
//MoLog.SrcSequence = Units[i].SrcSequence;
MoLog.DestNode = NodeID;
time_t ScheduleTime = (int)nowtime + Relay_Interval;
tmptime = localtime( &ScheduleTime);
sprintf( MoLog.SentTime, "%d%02d%02d%02d%02d%02d",
tmptime->tm_year + 1900,
tmptime->tm_mon + 1,
tmptime->tm_mday,
tmptime->tm_hour,
tmptime->tm_min,
tmptime->tm_sec);
(char)MoLog.Result = -1; //-1表示超时无应答
MoLog.Deliver = (CMPP_Deliver *)Units[i].Pack;
MyDB->WrMO_Queue(&MoLog,TAB_MO_Queue); //写上行转发记录缓存表
sprintf(sSysEvent,"Warning: A TimeOut CMPP_Deliver to DnNode[%s] is saved to MO_Queue temporarily!",ServiceCode);
WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG);
}
else
{
#ifdef DEBUG
printf("\n DnSentQCheck: An unsentable CMPP_Pack[%d] to DnNode[%s] is deleted and free!\n",PackSeq,ServiceCode);
#endif
}
free(Units[i].Pack); //删除包,释放内存
}
}//if()等待时间已到的数据包
}//for()
free(Units);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -