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


C++ Msg::Len方法代码示例

本文整理汇总了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());
}
开发者ID:iamethan,项目名称:EServer,代码行数:67,代码来源:Stub.cpp


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