fix for arguments that are now const NLPacket&

This commit is contained in:
Stephen Birarda 2015-07-09 11:31:57 -07:00
parent 765265abd8
commit c903d284bb
3 changed files with 12 additions and 8 deletions

View file

@ -38,7 +38,7 @@ void SentPacketHistory::packetSent(uint16_t sequenceNumber, const NLPacket& pack
_sentPackets.insert(NLPacket::createCopy(packet)); _sentPackets.insert(NLPacket::createCopy(packet));
} }
const NLPacket& SentPacketHistory::getPacket(uint16_t sequenceNumber) const { const NLPacket* SentPacketHistory::getPacket(uint16_t sequenceNumber) const {
const int UINT16_RANGE = std::numeric_limits<uint16_t>::max() + 1; const int UINT16_RANGE = std::numeric_limits<uint16_t>::max() + 1;
@ -48,6 +48,10 @@ const NLPacket& SentPacketHistory::getPacket(uint16_t sequenceNumber) const {
if (seqDiff < 0) { if (seqDiff < 0) {
seqDiff += UINT16_RANGE; seqDiff += UINT16_RANGE;
} }
auto packet = _sentPackets.get(seqDiff);
return *_sentPackets.get(seqDiff)->get(); if (packet) {
return packet->get();
} else {
return nullptr;
}
} }

View file

@ -25,7 +25,7 @@ public:
SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP); SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP);
void packetSent(uint16_t sequenceNumber, const NLPacket& packet); void packetSent(uint16_t sequenceNumber, const NLPacket& packet);
const NLPacket& getPacket(uint16_t sequenceNumber) const; const NLPacket* getPacket(uint16_t sequenceNumber) const;
private: private:
RingBufferHistory<std::unique_ptr<NLPacket>> _sentPackets; // circular buffer RingBufferHistory<std::unique_ptr<NLPacket>> _sentPackets; // circular buffer

View file

@ -108,7 +108,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu
} }
// add packet to history // add packet to history
_sentPacketHistories[nodeUUID].packetSent(sequence, packet); _sentPacketHistories[nodeUUID].packetSent(sequence, *packet.get());
queuePacketForSending(node, std::move(packet)); queuePacketForSending(node, std::move(packet));
} }
@ -186,7 +186,7 @@ void OctreeEditPacketSender::queuePacketToNodes(std::unique_ptr<NLPacket> packet
if (isMyJurisdiction) { if (isMyJurisdiction) {
// make a copy of this packet for this node and queue // make a copy of this packet for this node and queue
auto packetCopy = NLPacket::createCopy(packet); auto packetCopy = NLPacket::createCopy(*packet.get());
queuePacketToNode(nodeUUID, std::move(packetCopy)); queuePacketToNode(nodeUUID, std::move(packetCopy));
} }
} }
@ -362,10 +362,10 @@ void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
dataAt += sizeof(unsigned short int); dataAt += sizeof(unsigned short int);
// retrieve packet from history // retrieve packet from history
const std::unique_ptr<NLPacket>& packet = sentPacketHistory.getPacket(sequenceNumber); const NLPacket* packet = sentPacketHistory.getPacket(sequenceNumber);
if (packet) { if (packet) {
const SharedNodePointer& node = DependencyManager::get<NodeList>()->nodeWithUUID(sendingNodeUUID); const SharedNodePointer& node = DependencyManager::get<NodeList>()->nodeWithUUID(sendingNodeUUID);
queuePacketForSending(node, NLPacket::createCopy(packet)); queuePacketForSending(node, NLPacket::createCopy(*packet));
} }
} }
} }