From 3858e6933fee0e2b2add6cf7832daa4a99d6da39 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jul 2015 17:30:01 -0700 Subject: [PATCH] open packets for reading and writing --- libraries/networking/src/NLPacket.cpp | 20 +++++++++++++++++--- libraries/networking/src/udt/Packet.cpp | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 6fa7c73d39..db4322bccd 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -30,7 +30,11 @@ qint64 NLPacket::localHeaderSize() const { } std::unique_ptr NLPacket::create(PacketType::Value type, qint64 size) { - return std::unique_ptr(new NLPacket(type, size)); + auto packet = std::unique_ptr(new NLPacket(type, size)); + + packet->open(QIODevice::WriteOnly); + + return packet; } std::unique_ptr NLPacket::fromReceivedPacket(std::unique_ptr data, qint64 size, @@ -42,12 +46,22 @@ std::unique_ptr NLPacket::fromReceivedPacket(std::unique_ptr dat Q_ASSERT(size >= 0); // allocate memory - return std::unique_ptr(new NLPacket(std::move(data), size, senderSockAddr)); + auto packet = std::unique_ptr(new NLPacket(std::move(data), size, senderSockAddr)); + + packet->open(QIODevice::ReadOnly); + + return packet; } std::unique_ptr NLPacket::createCopy(const NLPacket& other) { - return std::unique_ptr(new NLPacket(other)); + auto packet = std::unique_ptr(new NLPacket(other)); + + if (other.isOpen()) { + packet->open(other.openMode()); + } + + return packet; } NLPacket::NLPacket(PacketType::Value type, qint64 size) : Packet(type, localHeaderSize(type) + size) { diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index f24da23edd..55c51d7665 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -22,7 +22,11 @@ qint64 Packet::maxPayloadSize(PacketType::Value type) { } std::unique_ptr Packet::create(PacketType::Value type, qint64 size) { - return std::unique_ptr(new Packet(type, size)); + auto packet = std::unique_ptr(new Packet(type, size)); + + packet->open(QIODevice::WriteOnly); + + return packet; } std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr) { @@ -30,11 +34,21 @@ std::unique_ptr Packet::fromReceivedPacket(std::unique_ptr data, q Q_ASSERT(size >= 0); // allocate memory - return std::unique_ptr(new Packet(std::move(data), size, senderSockAddr)); + auto packet = std::unique_ptr(new Packet(std::move(data), size, senderSockAddr)); + + packet->open(QIODevice::ReadOnly); + + return packet; } std::unique_ptr Packet::createCopy(const Packet& other) { - return std::unique_ptr(new Packet(other)); + auto packet = std::unique_ptr(new Packet(other)); + + if (other.isOpen()) { + packet->open(other.openMode()); + } + + return packet; } qint64 Packet::totalHeadersSize() const {