fix bugs from movement of type/version to NLPacket

This commit is contained in:
Stephen Birarda 2015-07-23 16:40:35 -07:00
parent 2f03075750
commit 069dff0793
4 changed files with 20 additions and 8 deletions

View file

@ -16,9 +16,9 @@ qint64 NLPacket::maxPayloadSize(PacketType type) {
}
qint64 NLPacket::localHeaderSize(PacketType type) {
qint64 size = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) +
qint64 optionalSize = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) +
((NON_SOURCED_PACKETS.contains(type) || NON_VERIFIED_PACKETS.contains(type)) ? 0 : NUM_BYTES_MD5_HASH);
return size;
return sizeof(PacketType) + sizeof(PacketVersion) + optionalSize;
}
qint64 NLPacket::maxPayloadSize() const {
@ -85,6 +85,8 @@ NLPacket::NLPacket(PacketType type, bool isReliable, bool isPartOfMessage) :
_version(versionForPacketType(type))
{
adjustPayloadStartAndCapacity();
writeTypeAndVersion();
}
NLPacket::NLPacket(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) :
@ -104,10 +106,14 @@ NLPacket::NLPacket(std::unique_ptr<Packet> packet) :
{
adjustPayloadStartAndCapacity(_payloadSize > 0);
readType();
readVersion();
readSourceID();
}
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
_type = other._type;
_version = other._version;
_sourceID = other._sourceID;
}
@ -125,14 +131,18 @@ NLPacket::NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr&
}
NLPacket::NLPacket(NLPacket&& other) :
Packet(other)
Packet(std::move(other))
{
_type = other._type;
_version = other._version;
_sourceID = std::move(other._sourceID);
}
NLPacket& NLPacket::operator=(const NLPacket& other) {
Packet::operator=(other);
_type = other._type;
_version = other._version;
_sourceID = other._sourceID;
return *this;
@ -142,6 +152,8 @@ NLPacket& NLPacket::operator=(NLPacket&& other) {
Packet::operator=(std::move(other));
_type = other._type;
_version = other._version;
_sourceID = std::move(other._sourceID);
return *this;
@ -188,8 +200,7 @@ void NLPacket::writeTypeAndVersion() {
memcpy(_packet.get() + headerOffset, &_type, sizeof(PacketType));
// Pack the packet version
auto version = versionForPacketType(_type);
memcpy(_packet.get() + headerOffset + sizeof(PacketType), &version, sizeof(version));
memcpy(_packet.get() + headerOffset + sizeof(PacketType), &_version, sizeof(_version));
}
void NLPacket::setType(PacketType type) {

View file

@ -533,8 +533,7 @@ void NodeList::sendAssignment(Assignment& assignment) {
QDataStream packetStream(assignmentPacket.get());
packetStream << assignment;
// TODO: should this be a non sourced packet?
sendPacket(std::move(assignmentPacket), _assignmentServerSocket);
}

View file

@ -80,6 +80,8 @@ BasePacket& BasePacket::operator=(const BasePacket& other) {
_payloadSize = other._payloadSize;
_senderSockAddr = other._senderSockAddr;
if (other.isOpen() && !isOpen()) {
open(other.openMode());
}

View file

@ -97,7 +97,7 @@ Packet& Packet::operator=(const Packet& other) {
}
Packet::Packet(Packet&& other) :
BasePacket(other)
BasePacket(std::move(other))
{
_isReliable = other._isReliable;
_isPartOfMessage = other._isPartOfMessage;