From 5f592df6101e00d27c9f916272bc575cae1ed750 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 20 Jul 2015 15:14:07 -0700 Subject: [PATCH] don't seek in Packet before open --- libraries/networking/src/NLPacket.cpp | 8 +------- libraries/networking/src/udt/Packet.cpp | 13 ++++++------- libraries/networking/src/udt/Packet.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index c34e589eff..7a6503dbc3 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -64,13 +64,7 @@ std::unique_ptr NLPacket::fromReceivedPacket(std::unique_ptr dat } std::unique_ptr NLPacket::createCopy(const NLPacket& other) { - auto packet = std::unique_ptr(new NLPacket(other)); - - if (other.isOpen()) { - packet->open(other.openMode()); - } - - return packet; + return std::unique_ptr(new NLPacket(other)); } NLPacket::NLPacket(PacketType::Value type, qint64 size) : diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index 5be229e129..02a44c4a4f 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -44,13 +44,7 @@ std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, q } std::unique_ptr Packet::createCopy(const Packet& other) { - auto packet = std::unique_ptr(new Packet(other)); - - if (other.isOpen()) { - packet->open(other.openMode()); - } - - return packet; + return std::unique_ptr(new Packet(other)); } qint64 Packet::totalHeadersSize() const { @@ -104,6 +98,11 @@ Packet::Packet(const Packet& other) : QIODevice() { *this = other; + + if (other.isOpen()) { + this->open(other.openMode()); + } + this->seek(other.pos()); } diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index 33fa8134bc..b4c53b8165 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -81,7 +81,7 @@ public: using QIODevice::read; QByteArray read(qint64 maxSize); - + template qint64 peekPrimitive(T* data); template qint64 readPrimitive(T* data); template qint64 writePrimitive(const T& data);