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++; }
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++; }