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


C++ NetBuffer::GetCurLength方法代码示例

本文整理汇总了C++中NetBuffer::GetCurLength方法的典型用法代码示例。如果您正苦于以下问题:C++ NetBuffer::GetCurLength方法的具体用法?C++ NetBuffer::GetCurLength怎么用?C++ NetBuffer::GetCurLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetBuffer的用法示例。


在下文中一共展示了NetBuffer::GetCurLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SendFragmented

void NetChannel::SendFragmented(NetBuffer& buffer)
{
	uint32_t outSequence = m_outSequence | 0x80000000;
	uint32_t remaining = buffer.GetCurLength();
	uint16_t i = 0;

	assert(buffer.GetCurLength() < 65536);

	while (remaining >= 0)
	{
		uint16_t thisSize = min(remaining, FRAGMENT_SIZE);

		// build this packet
		static char msgBuffer[FRAGMENT_SIZE + 100];
		*(uint32_t*)(&msgBuffer[0]) = outSequence;
		*(uint16_t*)(&msgBuffer[4]) = i;
		*(uint16_t*)(&msgBuffer[6]) = thisSize;
		memcpy(&msgBuffer[8], buffer.GetBuffer() + i, thisSize);

		m_netLibrary->SendData(m_targetAddress, msgBuffer, thisSize + 8);

		// decrement counters
		remaining -= thisSize;
		i += thisSize;

		// if the last packet didn't measure the fragment size
		if (remaining == 0 && thisSize != FRAGMENT_SIZE)
		{
			break;
		}
	}

	m_outSequence++;
}
开发者ID:ByModzMaster,项目名称:client,代码行数:34,代码来源:NetChannel.cpp

示例2: Send

void NetChannel::Send(NetBuffer& buffer)
{
	if (buffer.GetCurLength() > FRAGMENT_SIZE)
	{
		return SendFragmented(buffer);
	}

	static char msgBuffer[FRAGMENT_SIZE + 100];
	*(uint32_t*)(msgBuffer) = m_outSequence;
	memcpy(&msgBuffer[4], buffer.GetBuffer(), buffer.GetCurLength());

	m_netLibrary->SendData(m_targetAddress, msgBuffer, buffer.GetCurLength() + 4);

	m_outSequence++;
}
开发者ID:ByModzMaster,项目名称:client,代码行数:15,代码来源:NetChannel.cpp


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