mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 19:13:38 +02:00
open packets for reading and writing
This commit is contained in:
parent
3bf93063d7
commit
3858e6933f
2 changed files with 34 additions and 6 deletions
|
@ -30,7 +30,11 @@ qint64 NLPacket::localHeaderSize() const {
|
|||
}
|
||||
|
||||
std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, qint64 size) {
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
|
||||
auto packet = std::unique_ptr<NLPacket>(new NLPacket(type, size));
|
||||
|
||||
packet->open(QIODevice::WriteOnly);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
std::unique_ptr<NLPacket> NLPacket::fromReceivedPacket(std::unique_ptr<char> data, qint64 size,
|
||||
|
@ -42,12 +46,22 @@ std::unique_ptr<NLPacket> NLPacket::fromReceivedPacket(std::unique_ptr<char> dat
|
|||
Q_ASSERT(size >= 0);
|
||||
|
||||
// allocate memory
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(std::move(data), size, senderSockAddr));
|
||||
auto packet = std::unique_ptr<NLPacket>(new NLPacket(std::move(data), size, senderSockAddr));
|
||||
|
||||
packet->open(QIODevice::ReadOnly);
|
||||
|
||||
return packet;
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) {
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(other));
|
||||
auto packet = std::unique_ptr<NLPacket>(new NLPacket(other));
|
||||
|
||||
if (other.isOpen()) {
|
||||
packet->open(other.openMode());
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
NLPacket::NLPacket(PacketType::Value type, qint64 size) : Packet(type, localHeaderSize(type) + size) {
|
||||
|
|
|
@ -22,7 +22,11 @@ qint64 Packet::maxPayloadSize(PacketType::Value type) {
|
|||
}
|
||||
|
||||
std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
|
||||
return std::unique_ptr<Packet>(new Packet(type, size));
|
||||
auto packet = std::unique_ptr<Packet>(new Packet(type, size));
|
||||
|
||||
packet->open(QIODevice::WriteOnly);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
std::unique_ptr<Packet> Packet::fromReceivedPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr) {
|
||||
|
@ -30,11 +34,21 @@ std::unique_ptr<Packet> Packet::fromReceivedPacket(std::unique_ptr<char> data, q
|
|||
Q_ASSERT(size >= 0);
|
||||
|
||||
// allocate memory
|
||||
return std::unique_ptr<Packet>(new Packet(std::move(data), size, senderSockAddr));
|
||||
auto packet = std::unique_ptr<Packet>(new Packet(std::move(data), size, senderSockAddr));
|
||||
|
||||
packet->open(QIODevice::ReadOnly);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
|
||||
return std::unique_ptr<Packet>(new Packet(other));
|
||||
auto packet = std::unique_ptr<Packet>(new Packet(other));
|
||||
|
||||
if (other.isOpen()) {
|
||||
packet->open(other.openMode());
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
qint64 Packet::totalHeadersSize() const {
|
||||
|
|
Loading…
Reference in a new issue