OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_QUIC_ACK_NOTIFIER_MANAGER_H_ | 5 #ifndef NET_QUIC_QUIC_ACK_NOTIFIER_MANAGER_H_ |
6 #define NET_QUIC_QUIC_ACK_NOTIFIER_MANAGER_H_ | 6 #define NET_QUIC_QUIC_ACK_NOTIFIER_MANAGER_H_ |
7 | 7 |
8 #include <list> | |
9 #include <map> | 8 #include <map> |
10 #include <set> | |
11 | 9 |
| 10 #include "base/containers/hash_tables.h" |
12 #include "net/quic/quic_protocol.h" | 11 #include "net/quic/quic_protocol.h" |
13 | 12 |
| 13 #if defined(COMPILER_GCC) |
| 14 namespace BASE_HASH_NAMESPACE { |
| 15 template<> |
| 16 struct hash<net::QuicAckNotifier*> { |
| 17 std::size_t operator()(const net::QuicAckNotifier* ptr) const { |
| 18 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
| 19 } |
| 20 }; |
| 21 } |
| 22 #endif |
| 23 |
14 namespace net { | 24 namespace net { |
15 | 25 |
16 class QuicAckNotifier; | 26 class QuicAckNotifier; |
17 | 27 |
18 // The AckNotifierManager is used by the QuicConnection to keep track of all the | 28 // The AckNotifierManager is used by the QuicSentPacketManager to keep track of |
19 // AckNotifiers currently active. It owns the AckNotifiers which it gets from | 29 // all the AckNotifiers currently active. It owns the AckNotifiers which it gets |
20 // the serialized packets passed into OnSerializedPacket. It maintains both a | 30 // from the serialized packets passed into OnSerializedPacket. It maintains both |
21 // list of AckNotifiers and a map from sequence number to AckNotifier the sake | 31 // a set of AckNotifiers and a map from sequence number to AckNotifier the sake |
22 // of efficiency - we can quickly check the map to see if any AckNotifiers are | 32 // of efficiency - we can quickly check the map to see if any AckNotifiers are |
23 // interested in a given sequence number. | 33 // interested in a given sequence number. |
24 | 34 |
25 class NET_EXPORT_PRIVATE AckNotifierManager { | 35 class NET_EXPORT_PRIVATE AckNotifierManager { |
26 public: | 36 public: |
27 AckNotifierManager(); | 37 AckNotifierManager(); |
28 virtual ~AckNotifierManager(); | 38 virtual ~AckNotifierManager(); |
29 | 39 |
30 // Called from QuicConnection when it receives a new AckFrame. For each packet | 40 // Called when the connection receives a new AckFrame. For each packet |
31 // in |acked_packets|, if the packet sequence number exists in | 41 // in |acked_packets|, if the packet sequence number exists in |
32 // ack_notifier_map_ then the corresponding AckNotifiers will have their OnAck | 42 // ack_notifier_map_ then the corresponding AckNotifiers will have their OnAck |
33 // method called. | 43 // method called. |
34 void OnIncomingAck(const SequenceNumberSet& acked_packets); | 44 void OnIncomingAck(const SequenceNumberSet& acked_packets); |
35 | 45 |
36 // If a packet has been retransmitted with a new sequence number, then this | 46 // If a packet has been retransmitted with a new sequence number, then this |
37 // will be called. It updates the mapping in ack_notifier_map_, and also | 47 // will be called. It updates the mapping in ack_notifier_map_, and also |
38 // updates the internal list of sequence numbers in each matching AckNotifier. | 48 // updates the internal set of sequence numbers in each matching AckNotifier. |
39 void UpdateSequenceNumber(QuicPacketSequenceNumber old_sequence_number, | 49 void UpdateSequenceNumber(QuicPacketSequenceNumber old_sequence_number, |
40 QuicPacketSequenceNumber new_sequence_number); | 50 QuicPacketSequenceNumber new_sequence_number); |
41 | 51 |
42 // This is called after a packet has been serialized and is ready to be sent. | 52 // This is called after a packet has been serialized, is ready to be sent, and |
43 // If any of the frames in |serialized_packet| have AckNotifiers registered, | 53 // contains retransmittable frames (which may have associated AckNotifiers). |
44 // then add them to our internal map and additionally inform the AckNotifier | 54 // If any of the retransmittable frames included in |serialized_packet| have |
45 // of the sequence number which it should track. | 55 // AckNotifiers registered, then add them to our internal map and additionally |
| 56 // inform the AckNotifier of the sequence number which it should track. |
46 void OnSerializedPacket(const SerializedPacket& serialized_packet); | 57 void OnSerializedPacket(const SerializedPacket& serialized_packet); |
47 | 58 |
48 // Called from QuicConnection when data is sent which the sender would like to | |
49 // be notified on receipt of all ACKs. Adds the |notifier| to our map. | |
50 void AddAckNotifier(QuicAckNotifier* notifier); | |
51 | |
52 private: | 59 private: |
53 typedef std::list<QuicAckNotifier*> AckNotifierList; | 60 typedef base::hash_set<QuicAckNotifier*> AckNotifierSet; |
54 typedef std::set<QuicAckNotifier*> AckNotifierSet; | |
55 typedef std::map<QuicPacketSequenceNumber, AckNotifierSet> AckNotifierMap; | 61 typedef std::map<QuicPacketSequenceNumber, AckNotifierSet> AckNotifierMap; |
56 | 62 |
57 // On every ACK frame received by this connection, all the ack_notifiers_ will | 63 // On every ACK frame received by the connection, all the ack_notifiers_ will |
58 // be told which sequeunce numbers were ACKed. | 64 // be told which sequeunce numbers were ACKed. |
59 // Once a given QuicAckNotifier has seen all the sequence numbers it is | 65 // Once a given QuicAckNotifier has seen all the sequence numbers it is |
60 // interested in, it will be deleted, and removed from this list. | 66 // interested in, it will be deleted, and removed from this set. |
61 // Owns the AckNotifiers in this list. | 67 // Owns the AckNotifiers in this set. |
62 AckNotifierList ack_notifiers_; | 68 AckNotifierSet ack_notifiers_; |
63 | 69 |
64 // Maps from sequence number to the AckNotifiers which are registered | 70 // Maps from sequence number to the AckNotifiers which are registered |
65 // for that sequence number. On receipt of an ACK for a given sequence | 71 // for that sequence number. On receipt of an ACK for a given sequence |
66 // number, call OnAck for all mapped AckNotifiers. | 72 // number, call OnAck for all mapped AckNotifiers. |
67 // Does not own the AckNotifiers. | 73 // Does not own the AckNotifiers. |
68 std::map<QuicPacketSequenceNumber, AckNotifierSet> ack_notifier_map_; | 74 AckNotifierMap ack_notifier_map_; |
69 }; | 75 }; |
70 | 76 |
71 } // namespace net | 77 } // namespace net |
72 | 78 |
73 #endif // NET_QUIC_QUIC_ACK_NOTIFIER_MANAGER_H_ | 79 #endif // NET_QUIC_QUIC_ACK_NOTIFIER_MANAGER_H_ |
OLD | NEW |