| 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 #include "net/quic/quic_ack_notifier_manager.h" | 5 #include "net/quic/quic_ack_notifier_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | |
| 11 #include <utility> | 10 #include <utility> |
| 12 #include <vector> | 11 #include <vector> |
| 13 | 12 |
| 14 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 15 #include "net/quic/quic_ack_notifier.h" | 14 #include "net/quic/quic_ack_notifier.h" |
| 16 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 17 | 16 |
| 18 namespace net { | 17 namespace net { |
| 19 | 18 |
| 20 AckNotifierManager::AckNotifierManager() {} | 19 AckNotifierManager::AckNotifierManager() {} |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 set_it != map_it->second.end(); ++set_it) { | 38 set_it != map_it->second.end(); ++set_it) { |
| 40 (*set_it)->OnAck(*seq_it); | 39 (*set_it)->OnAck(*seq_it); |
| 41 } | 40 } |
| 42 | 41 |
| 43 // Remove the sequence number from the map as we have notified all the | 42 // Remove the sequence number from the map as we have notified all the |
| 44 // registered AckNotifiers, and we won't see it again. | 43 // registered AckNotifiers, and we won't see it again. |
| 45 ack_notifier_map_.erase(map_it); | 44 ack_notifier_map_.erase(map_it); |
| 46 } | 45 } |
| 47 | 46 |
| 48 // Clear up any empty AckNotifiers | 47 // Clear up any empty AckNotifiers |
| 49 AckNotifierList::iterator it = ack_notifiers_.begin(); | 48 AckNotifierSet::iterator it = ack_notifiers_.begin(); |
| 50 while (it != ack_notifiers_.end()) { | 49 while (it != ack_notifiers_.end()) { |
| 51 if ((*it)->IsEmpty()) { | 50 if ((*it)->IsEmpty()) { |
| 52 // The QuicAckNotifier has seen all the ACKs it was interested in, and | 51 // The QuicAckNotifier has seen all the ACKs it was interested in, and |
| 53 // has triggered its callback. No more use for it. | 52 // has triggered its callback. No more use for it. |
| 54 delete *it; | 53 delete *it; |
| 55 it = ack_notifiers_.erase(it); | 54 ack_notifiers_.erase(it++); |
| 56 } else { | 55 } else { |
| 57 ++it; | 56 ++it; |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 } | 59 } |
| 61 | 60 |
| 62 void AckNotifierManager::UpdateSequenceNumber( | 61 void AckNotifierManager::UpdateSequenceNumber( |
| 63 QuicPacketSequenceNumber old_sequence_number, | 62 QuicPacketSequenceNumber old_sequence_number, |
| 64 QuicPacketSequenceNumber new_sequence_number) { | 63 QuicPacketSequenceNumber new_sequence_number) { |
| 65 AckNotifierMap::iterator map_it = ack_notifier_map_.find(old_sequence_number); | 64 AckNotifierMap::iterator map_it = ack_notifier_map_.find(old_sequence_number); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 ack_notifier_map_[new_sequence_number] = new_set; | 76 ack_notifier_map_[new_sequence_number] = new_set; |
| 78 ack_notifier_map_.erase(map_it); | 77 ack_notifier_map_.erase(map_it); |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 | 80 |
| 82 void AckNotifierManager::OnSerializedPacket( | 81 void AckNotifierManager::OnSerializedPacket( |
| 83 const SerializedPacket& serialized_packet) { | 82 const SerializedPacket& serialized_packet) { |
| 84 // Run through all the frames and if any of them are stream frames and have | 83 // Run through all the frames and if any of them are stream frames and have |
| 85 // an AckNotifier registered, then inform the AckNotifier that it should be | 84 // an AckNotifier registered, then inform the AckNotifier that it should be |
| 86 // interested in this packet's sequence number. | 85 // interested in this packet's sequence number. |
| 87 RetransmittableFrames* retransmittable_frames = | |
| 88 serialized_packet.retransmittable_frames; | |
| 89 if (retransmittable_frames) { | |
| 90 for (QuicFrames::const_iterator it = | |
| 91 retransmittable_frames->frames().begin(); | |
| 92 it != retransmittable_frames->frames().end(); ++it) { | |
| 93 if (it->type == STREAM_FRAME && it->stream_frame->notifier != NULL) { | |
| 94 // The AckNotifier needs to know it is tracking this packet's sequence | |
| 95 // number. | |
| 96 it->stream_frame->notifier->AddSequenceNumber( | |
| 97 serialized_packet.sequence_number); | |
| 98 | 86 |
| 99 // Update the mapping in the other direction, from sequence | 87 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; |
| 100 // number to AckNotifier. | 88 |
| 101 ack_notifier_map_[serialized_packet.sequence_number] | 89 // AckNotifiers can only be attached to retransmittable frames. |
| 102 .insert(it->stream_frame->notifier); | 90 if (!frames) { |
| 103 } | 91 return; |
| 92 } |
| 93 |
| 94 for (QuicFrames::const_iterator it = frames->frames().begin(); |
| 95 it != frames->frames().end(); ++it) { |
| 96 if (it->type == STREAM_FRAME && it->stream_frame->notifier != NULL) { |
| 97 // The AckNotifier needs to know it is tracking this packet's sequence |
| 98 // number. |
| 99 it->stream_frame->notifier->AddSequenceNumber( |
| 100 serialized_packet.sequence_number); |
| 101 |
| 102 // Add the AckNotifier to our set of AckNotifiers. |
| 103 ack_notifiers_.insert(it->stream_frame->notifier); |
| 104 |
| 105 // Update the mapping in the other direction, from sequence |
| 106 // number to AckNotifier. |
| 107 ack_notifier_map_[serialized_packet.sequence_number] |
| 108 .insert(it->stream_frame->notifier); |
| 104 } | 109 } |
| 105 } | 110 } |
| 106 } | 111 } |
| 107 | 112 |
| 108 void AckNotifierManager::AddAckNotifier(QuicAckNotifier* notifier) { | |
| 109 ack_notifiers_.push_back(notifier); | |
| 110 } | |
| 111 | |
| 112 } // namespace net | 113 } // namespace net |
| OLD | NEW |