From 862c788aecfc775229960864ce44f6cb7a57eb58 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 23 Jul 2015 15:27:32 -0700 Subject: [PATCH] move payload adjustments to Packet --- .../src/octree/OctreeQueryNode.cpp | 2 +- .../src/octree/OctreeSendThread.cpp | 6 +++--- libraries/networking/src/NLPacket.cpp | 10 ---------- libraries/networking/src/NLPacket.h | 2 -- libraries/networking/src/udt/Packet.cpp | 19 +++++++++++++------ libraries/networking/src/udt/Packet.h | 5 ++++- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/assignment-client/src/octree/OctreeQueryNode.cpp b/assignment-client/src/octree/OctreeQueryNode.cpp index 6395397c51..f342f2e479 100644 --- a/assignment-client/src/octree/OctreeQueryNode.cpp +++ b/assignment-client/src/octree/OctreeQueryNode.cpp @@ -24,7 +24,7 @@ OctreeQueryNode::OctreeQueryNode() : _viewSent(false), _octreePacket(), _octreePacketWaiting(false), - _lastOctreePayload(new char[MAX_PACKET_SIZE]), + _lastOctreePayload(new char[udt::MAX_PACKET_SIZE]), _lastOctreePacketLength(0), _duplicatePacketCount(0), _firstSuppressedPacket(usecTimestampNow()), diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 62517e698b..417df3204a 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -219,7 +219,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes packetSent = true; int packetSizeWithHeader = nodeData->getPacket().getDataSize(); - thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader; + thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader; _totalWastedBytes += thisWastedBytes; _totalBytes += nodeData->getPacket().getDataSize(); _totalPackets++; @@ -251,7 +251,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes packetSent = true; int packetSizeWithHeader = nodeData->getPacket().getDataSize(); - int thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader; + int thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader; _totalWastedBytes += thisWastedBytes; _totalBytes += packetSizeWithHeader; _totalPackets++; @@ -598,7 +598,7 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus _totalBytes += packet->getDataSize(); _totalPackets++; - _totalWastedBytes += MAX_PACKET_SIZE - packet->getDataSize(); + _totalWastedBytes += udt::MAX_PACKET_SIZE - packet->getDataSize(); } } diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 221ef7da98..3660ac9ba2 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -207,16 +207,6 @@ void NLPacket::readVersion() { _version = NLPacket::versionInHeader(*this); } -void NLPacket::adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize) { - qint64 headerSize = localHeaderSize(_type); - _payloadStart += headerSize; - _payloadCapacity -= headerSize; - - if (shouldDecreasePayloadSize) { - _payloadSize -= headerSize; - } -} - void NLPacket::readSourceID() { if (!NON_SOURCED_PACKETS.contains(_type)) { _sourceID = sourceIDInHeader(*this); diff --git a/libraries/networking/src/NLPacket.h b/libraries/networking/src/NLPacket.h index cd2168cc4e..11ec40a294 100644 --- a/libraries/networking/src/NLPacket.h +++ b/libraries/networking/src/NLPacket.h @@ -65,8 +65,6 @@ protected: NLPacket& operator=(const NLPacket& other); NLPacket& operator=(NLPacket&& other); - void adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize = false); - // Header writers void writePacketTypeAndVersion(); diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index 3746f877ba..335f7e1d17 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -62,8 +62,7 @@ Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) : _isReliable(isReliable), _isPartOfMessage(isPartOfMessage) { - _payloadCapacity = size; - _payloadStart = _packet.get() + (_packetSize - _payloadCapacity); + adjustPayloadStartAndCapacity(); // set the UDT header to default values writeSequenceNumber(0); @@ -75,10 +74,8 @@ Packet::Packet(std::unique_ptr data, qint64 size, const HifiSockAddr& send readIsReliable(); readIsPartOfMessage(); readSequenceNumber(); - - _payloadCapacity = _packetSize - localHeaderSize(); - _payloadSize = _payloadCapacity; - _payloadStart = _packet.get() + (_packetSize - _payloadCapacity); + + adjustPayloadStartAndCapacity(_payloadSize > 0); } Packet::Packet(const Packet& other) : @@ -117,6 +114,16 @@ Packet& Packet::operator=(Packet&& other) { return *this; } +void Packet::adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize) { + qint64 headerSize = localHeaderSize(); + _payloadStart += headerSize; + _payloadCapacity -= headerSize; + + if (shouldDecreasePayloadSize) { + _payloadSize -= headerSize; + } +} + static const uint32_t CONTROL_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 1); static const uint32_t RELIABILITY_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 2); static const uint32_t MESSAGE_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 3); diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index e33a075a1f..39770bb022 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -56,9 +56,12 @@ protected: Packet(qint64 size, bool isReliable = false, bool isPartOfMessage = false); Packet(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); Packet(const Packet& other); - Packet& operator=(const Packet& other); Packet(Packet&& other); + + Packet& operator=(const Packet& other); Packet& operator=(Packet&& other); + + virtual void adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize = false); // Header readers - these read data to member variables after pulling packet off wire void readIsPartOfMessage();