本文整理汇总了C++中Msg::Len方法的典型用法代码示例。如果您正苦于以下问题:C++ Msg::Len方法的具体用法?C++ Msg::Len怎么用?C++ Msg::Len使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg::Len方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnRead
void Stub::OnRead(ssize_t nread, uv_buf_t buff)
{
GTimer timer;
m_uInputBufferPos += nread;
if (STUB_INPUTBUFFER_SIZE - m_uInputBufferPos < STUB_INPUTBUFFER_SIZE/4) {
g_Log.SaveLog(LOG_LV_ERROR, "Stub alloc error! used too much<%d, %d>", STUB_INPUTBUFFER_SIZE, m_uInputBufferPos);
Close();
return;
}
size_t nStartPos = 0;
MSG_ID_t uMsgID;
MSG_LEN_t uMsgLen;
size_t uIDLen = sizeof(uMsgID);
size_t uLenLen = sizeof(uMsgLen);
size_t uMsgTotalLen = 0;
while (nStartPos + uIDLen + uLenLen <= m_uInputBufferPos) {
memcpy(&uMsgID, m_pInputBuffers + nStartPos, uIDLen);
memcpy(&uMsgLen, m_pInputBuffers + nStartPos + uIDLen, uLenLen);
uMsgTotalLen = uIDLen + uLenLen + uMsgLen;
if (uMsgLen > STUB_INPUTBUFFER_SIZE / 2) {
g_Log.SaveLog(LOG_LV_ERROR, "Stub read Error! illegality msg<%d, %d> from<%s,>", uMsgID, uMsgLen, m_sIP.c_str());
Close();
break;
}
if (nStartPos + uMsgTotalLen > m_uInputBufferPos) {
break;
}
IMsgFactory* pFactory = g_MsgFactoryManager.GetFactory(uMsgID);
if (pFactory == NULL) {
g_Log.SaveLog(LOG_LV_WARNING, "Stub Read Warning! can not find the factory<id:%d, len:%d>", uMsgID, uMsgLen);
} else {
Msg* pMsg = pFactory->GetMsg();
if (pMsg == NULL) {
g_Log.SaveLog(LOG_LV_ERROR, "Stub Read Warning! create msg<id:%d, len:%d> failed!", uMsgID, uMsgLen);
} else {
pMsg->Len(uMsgLen);
if (!pFactory->Read(pMsg, m_pInputBuffers + nStartPos + uIDLen + uLenLen, uMsgLen)) {
g_Log.SaveLog(LOG_LV_ERROR, "Stub Read Warning! read<id:%d, len:%d> failed!", uMsgID, uMsgLen);
} else {
pFactory->HandleMsg(pMsg, this);
}
}
}
nStartPos += uMsgTotalLen;
}
assert(m_uInputBufferPos >= nStartPos);
size_t uLeft = m_uInputBufferPos - nStartPos;
if (uLeft > 0 && nStartPos > 0) {
memcpy(m_pInputBuffers, m_pInputBuffers + nStartPos, uLeft);
}
m_uInputBufferPos = uLeft;
//g_Log.SaveLog(LOG_LV_NORMAL, "cost time:%f", timer.Seconds());
}