From b5eb4945ab05a9a21342bd9df62140580331114b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 Jul 2015 16:06:09 -0700 Subject: [PATCH] fix packet segmentation in PacketList --- libraries/networking/src/PacketList.cpp | 8 ++++---- libraries/networking/src/PacketList.h | 4 ++-- libraries/networking/src/SentPacketHistory.cpp | 2 +- libraries/networking/src/SentPacketHistory.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/networking/src/PacketList.cpp b/libraries/networking/src/PacketList.cpp index 31b793cc76..77e1855fe0 100644 --- a/libraries/networking/src/PacketList.cpp +++ b/libraries/networking/src/PacketList.cpp @@ -20,10 +20,10 @@ PacketList::PacketList(PacketType::Value packetType, bool isOrdered) : void PacketList::createPacketWithExtendedHeader() { // use the static create method to create a new packet - _currentPacket = T::create(_packetType); + auto packet = T::create(_packetType); // add the extended header to the front of the packet - if (_currentPacket.write(_extendedHeader) == -1) { + if (packet->write(_extendedHeader) == -1) { qDebug() << "Could not write extendedHeader in PacketList::createPacketWithExtendedHeader" << "- make sure that _extendedHeader is not larger than the payload capacity."; } @@ -32,7 +32,7 @@ void PacketList::createPacketWithExtendedHeader() { qint64 writeData(const char* data, qint64 maxSize) { if (!_currentPacket) { // we don't have a current packet, time to set one up - createPacketWithExtendedHeader(); + _currentPacket = createPacketWithExtendedHeader(); } // check if this block of data can fit into the currentPacket @@ -46,7 +46,7 @@ qint64 writeData(const char* data, qint64 maxSize) { // it does not fit - this may need to be in the next packet if (!_isOrdered) { - auto newPacket = T::create(_packetType); + auto newPacket = createPacketWithExtendedHeader(); if (_segmentStartIndex >= 0) { // We in the process of writing a segment for an unordered PacketList. diff --git a/libraries/networking/src/PacketList.h b/libraries/networking/src/PacketList.h index 1b0905a1c8..356d357291 100644 --- a/libraries/networking/src/PacketList.h +++ b/libraries/networking/src/PacketList.h @@ -30,7 +30,7 @@ protected: qint64 writeData(const char* data, qint64 maxSize); qint64 readData(const char* data, qint64 maxSize) { return 0 }; private: - void createPacketWithExtendedHeader(); + std::unique_ptr createPacketWithExtendedHeader(); PacketType::Value _packetType; bool isOrdered; @@ -41,6 +41,6 @@ private: int _segmentStartIndex = -1; QByteArray _extendedHeader = extendedHeader; -} +}; #endif // hifi_PacketList_h diff --git a/libraries/networking/src/SentPacketHistory.cpp b/libraries/networking/src/SentPacketHistory.cpp index 3b0958f1ea..980646a082 100644 --- a/libraries/networking/src/SentPacketHistory.cpp +++ b/libraries/networking/src/SentPacketHistory.cpp @@ -30,7 +30,7 @@ void SentPacketHistory::packetSent(uint16_t sequenceNumber, const NLPacket& pack << "Expected:" << expectedSequenceNumber << "Actual:" << sequenceNumber; } _newestSequenceNumber = sequenceNumber; - _sentPackets.insert(new NLPacket(packet)); + _sentPackets.insert(NLPacket::createCopy(packet)); } const QByteArray* SentPacketHistory::getPacket(uint16_t sequenceNumber) const { diff --git a/libraries/networking/src/SentPacketHistory.h b/libraries/networking/src/SentPacketHistory.h index 566fd2dbfc..04cfdb3d36 100644 --- a/libraries/networking/src/SentPacketHistory.h +++ b/libraries/networking/src/SentPacketHistory.h @@ -23,10 +23,10 @@ public: SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP); void packetSent(uint16_t sequenceNumber, const NLPacket& packet); - const NLPacket* getPacket(uint16_t sequenceNumber) const; + const std::unique_ptr& getPacket(uint16_t sequenceNumber) const; private: - RingBufferHistory _sentPackets; // circular buffer + RingBufferHistory> _sentPackets; // circular buffer uint16_t _newestSequenceNumber; };