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

📄 dncmppdeal.cpp.bak

📁 SMS gateway. SMS protocol for CHINA mobile, unicom, lingtong. Using mysql to exchange message.
💻 BAK
📖 第 1 页 / 共 2 页
字号:
				tmptime->tm_sec);
			MoLog.SrcNode = SUnit.SrcNode;
			//MoLog.SrcSequence = SUnit.SrcSequence;
			memcpy(&MoLog.SrcMsgId , &SUnit.ID_Relate, sizeof(MoLog.SrcMsgId));
			MoLog.DestNode = DnNode->NodeID;
			MoLog.Result = pDeliverRsp->Result;
			MoLog.RelayTimes = SUnit.RelayTimes + 1;
			MoLog.Deliver = pDeliver;

			//检查应答状态,决定是否重发
			switch(pDeliverRsp->Result)
			{
			  case 0://正确应答
			  {
				  /*if((LOG_DB==0) || (LOG_DB==2))	//写入Submit转发日志文件
				  {
					  if((RetCode=WrSubmitLog->WriteLog(&SubmitLog,CMPP_SUBMITLOG))>0)
					  {
							sprintf(sSysEvent,"Error[%d]: DnCMPPDeal Writing CMPP_Submit pack into Log File!",RetCode); 
							WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG);    //写系统日志
							break;
					  }
				  }*/
				  //将MO转发记录写入数据表,成功转发的状态报告不写入MO转发记录??!!!
				  if(LOG_DB > 0 && pDeliver->Registered_Delivery==0)
				  {
					tmptime	= localtime( &pUnit->RecvTime);
					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);
					MyDB->WrCMPP_MOLog(&MoLog,TAB_CMPP_MO);	//写CMPP_Deliver上行转发记录表
				  }

				  //------------------------------------------------------------
				  free(SUnit.Pack);	//释放Submit包所占内存
				  #ifdef DEBUG
				  printf("\n DnCMPPDeal[%s]: A successfully Sent CMPP_Deliver[%d] to DnNode[%d] is saved to DB.CMPP_MOLog.!\n",timebuf,ntohl(pDeliver->Head.Sequence_Id),DnNode->NodeID);
				  #endif

				  break;
			  }
			  case 1:
			  case 2:
			  case 3:
			  case 4:
			  case 5:
			  case 6:
			  case 7:
			  case 8:
			  default:	//各种错误响应码
			  {
				  if(SUnit.iResent)	//可重发的请求包,或者发送失败的应答包
				  {			
					    //存到待发送队列
						DnNode->SendQ->Wait_Put(SUnit);
						/*while(DnNode->SendQ->Put(SUnit)==false)
						{
							sprintf(sSysEvent,"Warning: Send Queue is full!Recv_Q_Full_Wait=[%d]!",Recv_Q_Full_Wait);
							WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); 
							usleep(Send_Q_Full_Wait);
						}*/
						#ifdef DEBUG
						printf("\n DnCMPPDeal[%s]: A CMPP_Submit Pack[%d] is transmited from SentQ to SendQ.\n",timebuf,ntohl(pDeliver->Head.Sequence_Id));
						#endif
				  }
				  else	//最大发送次数已满,仍未收到正确的应答包
				  {	
					  /*if((LOG_DB==0) || (LOG_DB==2))
					  {
						  //写入Submit_Failed日志文件
						  if((RetCode = WrSubmit_FailLog->WriteLog(&SubmitLog,CMPP_SUBMITLOG))>0)
						  {
								sprintf(sSysEvent,"Error[%d]: DnCMPPDeal Writing ??? File!",RetCode); 
								WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG);    //写系统日志
								break;
						  }
					  }*/
					  if(LOG_DB > 0)	//将失败的MO转发记录写入数据表,等待重发
					  {
						time_t Schedule = (int)pUnit->RecvTime + Relay_Interval;	
						tmptime	= localtime( &Schedule);
						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);
						//写上行转发记录缓存表
						MyDB->WrMO_Queue(&MoLog,TAB_MO_Queue);
						sprintf(sSysEvent,"Warning: A CMPP_Deliver to DnNode[%s] is saved to MO_Queue temporarily!",DnNode->ServiceCode);
						WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); 
					  }
					  
					  //------------------------------------------------------------
					  free(SUnit.Pack);	//删除包,释放内存
					  #ifdef DEBUG
					  int UnitNum = DnNode->SentQ.GetSize();	//获取已发送窗口的占用数
					  printf("\n DnCMPPDeal[%s]: An unsentable CMPP_Deliver[%d] to DnNode[%d] is deleted and clean! SentQ_Size=[%d]\n",timebuf,ntohl(pDeliver->Head.Sequence_Id),DnNode->NodeID,UnitNum);
					  #endif
				  }

				  break;
			  }//default,其他错误码
			}//switch(pDeliverRsp->Result)
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		case CMPP_ACTIVE_TEST_RESP:
		{
			CMPP_Active_Test *pActiveTest;
			pActiveTest = (CMPP_Active_Test *)pUnit->Pack;

			//从已发送队列中删除对应的等应答的单元,并释放原ActiveTest包所占内存
			if(DnNode->SentQ.Clean(ntohl(pActiveTest->Sequence_Id)) == false)
			{
				sprintf(sSysEvent," Error: DnCMPPDeal Can't find the corresponding CMPP_ActiveTest Pack[%d]!\n",ntohl(pActiveTest->Sequence_Id));
				WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); 
			}
			else
			{
				#ifdef DEBUG
				//printf("\n DnCMPPDeal: The corresponding ActiveTest Pack[%d] is clean!\n",ntohl(pActiveTest->Sequence_Id));
				#endif
			}

			#ifdef DEBUG
			int UnitNum = DnNode->SentQ.GetSize();	//获取已发送窗口的占用数
		    printf("\n DnCMPPDeal[%s]: A CMPP_ACTIVE_TEST_RESP[%d] from DnNode[%d] is dealed, SentQ_Size=[%d] \n",timebuf,ntohl(pActiveTest->Sequence_Id),DnNode->NodeID,UnitNum);			    
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		case CMPP_ACTIVE_TEST:
		{
			#ifdef DEBUG
			printf("\n DnCMPPDeal: Got an CMPP_ACTIVE_TEST[%x] from DnNode[%d]!\n",Sequence,DnNode->NodeID);
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		case CMPP_TERMINATE:
		{
			#ifdef DEBUG
			printf("\n DnCMPPDeal: Got an CMPP_TERMINATE[%x] from DnNode[%d]!\n",Sequence,DnNode->NodeID);
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		case CMPP_TERMINATE_RESP:
		{
			#ifdef DEBUG
			printf("\n DnCMPPDeal: Got an CMPP_TERMINATE_RESP[%x] from DnNode[%d]!\n",Sequence,DnNode->NodeID);
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		case CMPP_QUERY:
		{
			#ifdef DEBUG
			printf("\n DnCMPPDeal: Got an CMPP_QUERY_RESP[%x] from DnNode[%d]!\n",Sequence,DnNode->NodeID);
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		case CMPP_CANCEL:
		{
			#ifdef DEBUG
			printf("\n DnCMPPDeal: Got an CMPP_CANCEL_RESP[%x] from DnNode[%d]!\n",Sequence,DnNode->NodeID);
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
		//================================================================
		default:
		{
			#ifdef DEBUG
			printf("\n DnCMPPDeal: Got an Unexpected CMPP pack[%x] from DnNode[%d],Sequence=[%x]. Packlen=%d.\n",PackType,DnNode->NodeID,Sequence,ntohl(*(int *)pUnit->Pack));
			#endif
			free(pUnit->Pack);	//释放接收包所占内存,在TCPsocket::RecvPack()中malloc
			break;
		}
	}//switch()

  free(pUnit);	//释放接收单元所占内存,在CGateWay::Dn_RecvQ_Poller()中malloc,在此free是为了多线程
  return (void *)NULL;
}

⌨️ 快捷键说明

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