move payload adjustments to Packet

This commit is contained in:
Stephen Birarda 2015-07-23 15:27:32 -07:00
parent df47f1dd0b
commit 862c788aec
6 changed files with 21 additions and 23 deletions

View file

@ -24,7 +24,7 @@ OctreeQueryNode::OctreeQueryNode() :
_viewSent(false), _viewSent(false),
_octreePacket(), _octreePacket(),
_octreePacketWaiting(false), _octreePacketWaiting(false),
_lastOctreePayload(new char[MAX_PACKET_SIZE]), _lastOctreePayload(new char[udt::MAX_PACKET_SIZE]),
_lastOctreePacketLength(0), _lastOctreePacketLength(0),
_duplicatePacketCount(0), _duplicatePacketCount(0),
_firstSuppressedPacket(usecTimestampNow()), _firstSuppressedPacket(usecTimestampNow()),

View file

@ -219,7 +219,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
packetSent = true; packetSent = true;
int packetSizeWithHeader = nodeData->getPacket().getDataSize(); int packetSizeWithHeader = nodeData->getPacket().getDataSize();
thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader; thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes; _totalWastedBytes += thisWastedBytes;
_totalBytes += nodeData->getPacket().getDataSize(); _totalBytes += nodeData->getPacket().getDataSize();
_totalPackets++; _totalPackets++;
@ -251,7 +251,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
packetSent = true; packetSent = true;
int packetSizeWithHeader = nodeData->getPacket().getDataSize(); int packetSizeWithHeader = nodeData->getPacket().getDataSize();
int thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader; int thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes; _totalWastedBytes += thisWastedBytes;
_totalBytes += packetSizeWithHeader; _totalBytes += packetSizeWithHeader;
_totalPackets++; _totalPackets++;
@ -598,7 +598,7 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
_totalBytes += packet->getDataSize(); _totalBytes += packet->getDataSize();
_totalPackets++; _totalPackets++;
_totalWastedBytes += MAX_PACKET_SIZE - packet->getDataSize(); _totalWastedBytes += udt::MAX_PACKET_SIZE - packet->getDataSize();
} }
} }

View file

@ -207,16 +207,6 @@ void NLPacket::readVersion() {
_version = NLPacket::versionInHeader(*this); _version = NLPacket::versionInHeader(*this);
} }
void NLPacket::adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize) {
qint64 headerSize = localHeaderSize(_type);
_payloadStart += headerSize;
_payloadCapacity -= headerSize;
if (shouldDecreasePayloadSize) {
_payloadSize -= headerSize;
}
}
void NLPacket::readSourceID() { void NLPacket::readSourceID() {
if (!NON_SOURCED_PACKETS.contains(_type)) { if (!NON_SOURCED_PACKETS.contains(_type)) {
_sourceID = sourceIDInHeader(*this); _sourceID = sourceIDInHeader(*this);

View file

@ -65,8 +65,6 @@ protected:
NLPacket& operator=(const NLPacket& other); NLPacket& operator=(const NLPacket& other);
NLPacket& operator=(NLPacket&& other); NLPacket& operator=(NLPacket&& other);
void adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize = false);
// Header writers // Header writers
void writePacketTypeAndVersion(); void writePacketTypeAndVersion();

View file

@ -62,8 +62,7 @@ Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) :
_isReliable(isReliable), _isReliable(isReliable),
_isPartOfMessage(isPartOfMessage) _isPartOfMessage(isPartOfMessage)
{ {
_payloadCapacity = size; adjustPayloadStartAndCapacity();
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
// set the UDT header to default values // set the UDT header to default values
writeSequenceNumber(0); writeSequenceNumber(0);
@ -76,9 +75,7 @@ Packet::Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& send
readIsPartOfMessage(); readIsPartOfMessage();
readSequenceNumber(); readSequenceNumber();
_payloadCapacity = _packetSize - localHeaderSize(); adjustPayloadStartAndCapacity(_payloadSize > 0);
_payloadSize = _payloadCapacity;
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
} }
Packet::Packet(const Packet& other) : Packet::Packet(const Packet& other) :
@ -117,6 +114,16 @@ Packet& Packet::operator=(Packet&& other) {
return *this; 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 CONTROL_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 1);
static const uint32_t RELIABILITY_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 2); static const uint32_t RELIABILITY_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 2);
static const uint32_t MESSAGE_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 3); static const uint32_t MESSAGE_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 3);

View file

@ -56,10 +56,13 @@ protected:
Packet(qint64 size, bool isReliable = false, bool isPartOfMessage = false); Packet(qint64 size, bool isReliable = false, bool isPartOfMessage = false);
Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr); Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr);
Packet(const Packet& other); Packet(const Packet& other);
Packet& operator=(const Packet& other);
Packet(Packet&& other); Packet(Packet&& other);
Packet& operator=(const Packet& other);
Packet& operator=(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 // Header readers - these read data to member variables after pulling packet off wire
void readIsPartOfMessage(); void readIsPartOfMessage();
void readIsReliable(); void readIsReliable();