本文整理汇总了C++中CNetMessage::GetMSGLen方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetMessage::GetMSGLen方法的具体用法?C++ CNetMessage::GetMSGLen怎么用?C++ CNetMessage::GetMSGLen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNetMessage
的用法示例。
在下文中一共展示了CNetMessage::GetMSGLen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecvPacketSlice
INT32 CNetChannel::RecvPacketSlice(StruCommuPacket* pCommuPacket)
{
fnNetEvent pNetEventFn;
void* pNetEventCaller;
CBufferObj* pFreeBuf;
INT32 iDone = 0;
INT32 iTotalLen = 0;
CNetMessage UserMsg;
INT32 iRet;
if(NULL == pCommuPacket)
{
CMM_ASSERT(0);
return -1;
}
if(pCommuPacket->Header.iSessionID != m_PrePacketHeader.iSessionID)//切换Session
{
if(0 == m_PrePacketHeader.iSessionID) //第一个包
{
}
else //Session 丢包了
{
LOG2_DEBUG( "ChnType(%d) %s:%d => %s:%d. Lost packet.\n",
GetChnType(),
GetLocalIPAddrString(),GetLocalPort(),
GetRemoteIPAddrString(),GetRemotePort());
//清空
m_MgrRecvBuffer.ClearBuffer();
//暂时不做重传处理
}
if(pCommuPacket->Header.iTotalPacket > 1)
{
memcpy(&m_PrePacketHeader, &pCommuPacket->Header, sizeof(StruCommuHeader));
}
else//只有1个包
{
iDone = 1;
}
pFreeBuf = m_pBufferArray->GetFreeBuffer();
if(NULL == pFreeBuf)
{
return -2;
}
pFreeBuf->SetData(this, pCommuPacket->Payload, pCommuPacket->Header.iLength);
m_MgrRecvBuffer.PushBuffer(pFreeBuf);
}
else
{
pFreeBuf = m_pBufferArray->GetFreeBuffer();
if(NULL == pFreeBuf)
{
LOG2_FATAL( "GetFreeBuffer fail.\n");
return -2;
}
pFreeBuf->SetData(this, pCommuPacket->Payload, pCommuPacket->Header.iLength);
m_MgrRecvBuffer.PushBuffer(pFreeBuf);
if(pCommuPacket->Header.iTotalPacket == pCommuPacket->Header.iCurPacket)
{
iDone = 1;
memset(&m_PrePacketHeader, 0, sizeof(m_PrePacketHeader));
}
}
if(iDone)
{
if(NULL == m_pRecvPackBuf || m_iRecvPackBufSize <= 0)
{
return -1;
}
iTotalLen = m_MgrRecvBuffer.GetDataLen();
if(iTotalLen > m_iRecvPackBufSize)
{
m_pExtRecvPackBuf = (char*)malloc(iTotalLen);
if(NULL == m_pExtRecvPackBuf)
{
LOG2_FATAL( "malloc %d fail.\n", iTotalLen);
return -2;
}
}
else
{
m_pExtRecvPackBuf = m_pRecvPackBuf;
}
m_MgrRecvBuffer.GetData(m_pExtRecvPackBuf);
m_MgrRecvBuffer.ClearBuffer();
iRet = DePacketUserMsg(m_pExtRecvPackBuf, &UserMsg);
if(UserMsg.GetMSGLen() > iTotalLen)
{
char* pTempMsg = (char*)malloc(UserMsg.GetMSGLen());
if(NULL == pTempMsg)
{
LOG2_FATAL( "malloc %d fail.\n", UserMsg.GetMSGLen());
return -2;
}
memcpy(pTempMsg, m_pExtRecvPackBuf, iTotalLen);
free(m_pExtRecvPackBuf);
//.........这里部分代码省略.........