예제 #1
0
int CEmsInfo::ReceiveStaRequestProcess(CProtocol &cProto)
{
    std::vector<char> vecPayload;
    CSessionInfo *cSessionInfo = NULL;
    CStmReqApi cDecApi;
    char *szPayload = NULL;
    char chFlag = 0;
    time_t tm = 0;

    tm = time(NULL);

    chFlag = cProto.GetFlag();

    if(chFlag != CProtocol::FLAG_REQUEST){
        STA_LOG(STA_ERR,"Invalid Flag(flag=%d)\n",chFlag);
        return STA_NOK;
    }

    cProto.GetPayload(vecPayload);

    cSessionInfo = new CSessionInfo();

    cSessionInfo->SetReceiveTime(tm);

    szPayload = new char[vecPayload.size() + 1];

    strncpy(szPayload, &vecPayload[0], vecPayload.size());
    szPayload[vecPayload.size()] = '\0';
    cSessionInfo->SetReceiveData(szPayload, vecPayload.size());

    DEBUG_LOG("RECEIVE DATA (Wait 3 time)\n");
    m_lstPendingQueue.push_back(cSessionInfo);

    return STA_OK;
}
예제 #2
0
int CMain::ReceiveIpcHandler()
{
	int cmdCode = 0;
	string strCmdCode;
	CGlobal *cGlob = NULL;
	CModuleIPC *cIpc = NULL;
	CProtocol cProto;
	char chFlag = 0;
	int nRet = 0;

	cGlob = CGlobal::GetInstance();

	cIpc = cGlob->GetModuleIPC();

	nRet = cIpc->RecvMesg(cGlob->GetLocalProcNo(), cProto, -1);
	if(nRet < 0){
		CLA_LOG(CLA_ERR,false,"Message receive failed(ERR:%s)\n", cIpc->m_strErrorMsg.c_str());
		return CLA_NOK;
	}
	else if(nRet == 0){
		return CLA_OK;
	}

	chFlag = cProto.GetFlag();

	if((chFlag != CProtocol::FLAG_RESPONSE)){
		CLA_LOG(CLA_ERR,false,"Invalid Flag(flag=%d)\n",chFlag);
		return CLA_NOK;
	}

	strCmdCode = cProto.GetCommand();

	cmdCode = CGlobal::GetCmdCode(strCmdCode);

	switch(cmdCode){
		case CMD_CLI_COMMAND:
			{
				unsigned int fd = 0;
				unsigned int nSessionId = 0;
				CCliPeer *cPeer = NULL;
				CSession *cSession = NULL;
				CCliRsp decRsp;
				string strPayload;

				nSessionId = cProto.GetSequence();

				cSession = FindSession(nSessionId);
				if(cSession == NULL){
					CLA_LOG(CLA_ERR,false,"Can not find session(id=%d)\n",nSessionId);
					return CLA_NOK;
				}

				strPayload = cProto.GetPayload();

				decRsp.DecodeMessage(strPayload);

				decRsp.SetSessionId(cSession->GetClcSessionId());

				decRsp.EncodeMessage(strPayload);

				cProto.SetPayload(strPayload);
				cProto.SetSequence(cSession->GetClcSessionId());

				fd = cSession->GetPeerFd();

				cPeer = FindPeerByFd(fd);
				if(cPeer == NULL){
					CLA_LOG(CLA_ERR,false,"Can not find peer(fd=%d)\n",fd);
					delete cSession;
					return CLA_NOK;
				}

				if(cPeer->GetTimestamp() != cSession->GetPeerTimestamp()){
					CLA_LOG(CLA_ERR,false,"Can not find peer(timestamp=%lu, %lu)\n", 
							cPeer->GetTimestamp() ,cSession->GetPeerTimestamp());
					delete cSession;
					return CLA_NOK;
				}

				/* update hist */
				UpdateHist(cPeer, cSession, &decRsp);

				cPeer->Send(cProto);

				delete cSession;
			}
			break;
		default :
			CLA_LOG(CLA_ERR,false,"Invalid cmdCode(%s)\n",cProto.GetCommand().c_str());
			return CLA_NOK;

	};


	return CLA_OK;
}