don't seek in Packet before open

This commit is contained in:
Stephen Birarda 2015-07-20 15:14:07 -07:00
parent 462ff97722
commit 5f592df610
3 changed files with 8 additions and 15 deletions

View file

@ -64,13 +64,7 @@ std::unique_ptr<NLPacket> NLPacket::fromReceivedPacket(std::unique_ptr<char> dat
} }
std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) { std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) {
auto packet = std::unique_ptr<NLPacket>(new NLPacket(other)); return std::unique_ptr<NLPacket>(new NLPacket(other));
if (other.isOpen()) {
packet->open(other.openMode());
}
return packet;
} }
NLPacket::NLPacket(PacketType::Value type, qint64 size) : NLPacket::NLPacket(PacketType::Value type, qint64 size) :

View file

@ -44,13 +44,7 @@ std::unique_ptr<Packet> Packet::fromReceivedPacket(std::unique_ptr<char> data, q
} }
std::unique_ptr<Packet> Packet::createCopy(const Packet& other) { std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
auto packet = std::unique_ptr<Packet>(new Packet(other)); return std::unique_ptr<Packet>(new Packet(other));
if (other.isOpen()) {
packet->open(other.openMode());
}
return packet;
} }
qint64 Packet::totalHeadersSize() const { qint64 Packet::totalHeadersSize() const {
@ -104,6 +98,11 @@ Packet::Packet(const Packet& other) :
QIODevice() QIODevice()
{ {
*this = other; *this = other;
if (other.isOpen()) {
this->open(other.openMode());
}
this->seek(other.pos()); this->seek(other.pos());
} }

View file

@ -81,7 +81,7 @@ public:
using QIODevice::read; using QIODevice::read;
QByteArray read(qint64 maxSize); QByteArray read(qint64 maxSize);
template<typename T> qint64 peekPrimitive(T* data); template<typename T> qint64 peekPrimitive(T* data);
template<typename T> qint64 readPrimitive(T* data); template<typename T> qint64 readPrimitive(T* data);
template<typename T> qint64 writePrimitive(const T& data); template<typename T> qint64 writePrimitive(const T& data);