本文整理汇总了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++;
}
示例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++;
}