Overte C++ Documentation
SentPacketHistory.h
1 //
2 // SentPacketHistory.h
3 // libraries/networking/src
4 //
5 // Created by Yixin Wang on 6/5/2014
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_SentPacketHistory_h
12 #define hifi_SentPacketHistory_h
13 
14 #include <stdint.h>
15 
16 #include <QtCore/QByteArray>
17 #include <QtCore/QReadWriteLock>
18 
19 #include "NLPacket.h"
20 #include "RingBufferHistory.h"
21 #include "SequenceNumberStats.h"
22 
23 class NLPacket;
24 
25 class SentPacketHistory {
26 
27 public:
28  SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP);
29 
30  void untrackedPacketSent(uint16_t sequenceNumber);
31 
32  void packetSent(uint16_t sequenceNumber, const NLPacket& packet);
33  const NLPacket* getPacket(uint16_t sequenceNumber) const;
34 
35 private:
36  mutable QReadWriteLock _packetsLock { QReadWriteLock::Recursive };
37  RingBufferHistory<std::unique_ptr<NLPacket>> _sentPackets; // circular buffer
38 
39  uint16_t _newestSequenceNumber;
40 };
41 
42 #endif