本文整理汇总了C++中Protocol::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ Protocol::GetType方法的具体用法?C++ Protocol::GetType怎么用?C++ Protocol::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hawk_EchoClientRoutine
PVoid hawk_EchoClientRoutine(void* pArg)
{
HawkSession session;
if (session.Init(g_IpAddr))
{
while (g_Running)
{
//更新
if (!session.Tick(PROTO_TIME))
break;
//发送协议
Int32 iType = HawkRand::RandInt(PROTO_A, PROTO_C);
if (iType == PROTO_A)
{
ProtoA sCmd;
session.SendProtocol(&sCmd);
}
else if (iType == PROTO_B)
{
ProtoB sCmd;
session.SendProtocol(&sCmd);
}
else if (iType == PROTO_C)
{
ProtoC sCmd;
session.SendProtocol(&sCmd);
}
//接收协议
Protocol* pProto = 0;
while (session.DecodeProtocol(pProto) && pProto)
{
#if (PRINT_PROTO == 1)
ProtoType iType = pProto->GetType();
if (iType == PROTO_A)
{
ProtoA* pA = (ProtoA*)pProto;
HawkFmtPrint("Msg: %s",pA->m_sMsg.c_str());
}
else if (iType == PROTO_B)
{
ProtoB* pB = (ProtoB*)pProto;
HawkFmtPrint("Size: %d, Time: %d",pB->m_iSize, pB->m_iTime);
}
else if (iType == PROTO_C)
{
ProtoC* pC = (ProtoC*)pProto;
HawkFmtPrint("X: %f, Y: %f, Z: %f",pC->m_fX, pC->m_fY, pC->m_fZ);
}
#endif
P_ProtocolManager->ReleaseProto(pProto);
}
HawkSleep(PROTO_TIME);
}
}
return 0;
}
示例2: Run
Bool HawkLogServer::Run()
{
if (!m_pLogFile && !m_pLogDB)
return false;
if (m_bRunning || !m_pRecvBuf || !m_pLogCache)
return false;
m_bRunning = true;
UInt32 iFlushTime = HawkOSOperator::GetTickCount();
while(m_bRunning)
{
UInt32 iCurTime = HawkOSOperator::GetTickCount();
if (!m_sSocket.UpdateEvent(HEVENT_READ))
{
if (iCurTime - iFlushTime >= (UInt32)m_iCacheTime)
{
FlushLogs();
iFlushTime = iCurTime;
}
else
{
HawkSleep(DEFAULT_SLEEP);
}
continue;
}
m_pRecvBuf->Clear();
Size_t iRecv = (Size_t)m_pRecvBuf->Capacity();
SocketAddr sAddr;
if(!m_sSocket.ReceiveFrom(m_pRecvBuf->Begin(), iRecv, sAddr))
continue;
m_pRecvBuf->Resize((UInt32)iRecv);
Protocol* pProto = 0;
try
{
pProto = P_ProtocolManager->Decode(*m_pRecvBuf);
if (!pProto) continue;
}
catch (HawkException& rhsExcep)
{
#ifdef _DEBUG
HawkFmtPrint("Exception: %s", rhsExcep.GetMsg().c_str());
#endif
continue;
}
ProtoType eType = pProto->GetType();
if(eType == SysProtocol::SYS_LOG_MSG)
{
SysProtocol::Sys_LogMsg* pCmd = (SysProtocol::Sys_LogMsg*)pProto;
CacheLogs(pCmd->m_iLogId, pCmd->m_iType, pCmd->m_sKey, pCmd->m_sMsg);
}
P_ProtocolManager->ReleaseProto(pProto);
}
FlushLogs();
return true;
}
示例3: RunLoop
Bool HawkProfiler::RunLoop()
{
UInt32 iCalcTime = HawkOSOperator::GetTickCount();
while(m_bRunning)
{
UInt32 iCurTime = HawkOSOperator::GetTickCount();
//定期计算CPU和内存使用情况
if (iCurTime - iCalcTime >= 1000)
{
GetCpuUsage();
GetMemUsage();
iCalcTime = iCurTime;
}
if (!m_sSocket.UpdateEvent(HEVENT_READ, DEFAULT_SLEEP))
continue;
m_pRecvBuf->Clear();
Size_t iRecv = (Size_t)m_pRecvBuf->Capacity();
SocketAddr sAddr;
if(!m_sSocket.ReceiveFrom(m_pRecvBuf->Begin(), iRecv, sAddr))
continue;
m_pRecvBuf->Resize((UInt32)iRecv);
Protocol* pProto = 0;
try
{
pProto = P_ProtocolManager->Decode(*m_pRecvBuf);
if (!pProto) continue;
}
catch (HawkException& rhsExcep)
{
HawkFmtPrint("Exception: %s", rhsExcep.GetMsg().c_str());
continue;
}
ProtoType eType = pProto->GetType();
if(eType == SysProtocol::SYS_PROF_REQ)
{
SysProtocol::Sys_ProfInfo sInfo;
sInfo.m_iTimeStamp = HawkOSOperator::GetTickCount();
sInfo.m_iCpuCount = m_iCpuCount;
sInfo.m_iTotalMem = m_iTotalMem;
sInfo.m_iCpuUsage = m_iCpuUsage;
sInfo.m_iMemUsage = m_iMemUsage;
sInfo.m_iConnect = m_iConnect;
sInfo.m_iRecvProto = m_iRecvProto;
sInfo.m_iRecvSize = m_iRecvSize;
sInfo.m_iSendProto = m_iSendProto;
sInfo.m_iSendSize = m_iSendSize;
m_pRecvBuf->Clear();
sInfo.Encode(*m_pRecvBuf);
Size_t iSize = (Size_t)m_pRecvBuf->Size();
m_sSocket.SendTo(m_pRecvBuf->Begin(), iSize, sAddr);
}
P_ProtocolManager->ReleaseProto(pProto);
}
return true;
}