| 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 <utility> | 10 #include <utility> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 QuicTime::Delta delta_largest_observed) { | 33 QuicTime::Delta delta_largest_observed) { |
| 34 // Inform all the registered AckNotifiers of the new ACK. | 34 // Inform all the registered AckNotifiers of the new ACK. |
| 35 auto map_it = ack_notifier_map_.find(sequence_number); | 35 auto map_it = ack_notifier_map_.find(sequence_number); |
| 36 if (map_it == ack_notifier_map_.end()) { | 36 if (map_it == ack_notifier_map_.end()) { |
| 37 // No AckNotifier is interested in this sequence number. | 37 // No AckNotifier is interested in this sequence number. |
| 38 return; | 38 return; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // One or more AckNotifiers are registered as interested in this sequence | 41 // One or more AckNotifiers are registered as interested in this sequence |
| 42 // number. Iterate through them and call OnAck on each. | 42 // number. Iterate through them and call OnAck on each. |
| 43 AckNotifierList& ack_notifier_list = map_it->second; | 43 for (QuicAckNotifier* ack_notifier : map_it->second) { |
| 44 for (QuicAckNotifier* ack_notifier : ack_notifier_list) { | 44 if (ack_notifier->OnAck(delta_largest_observed)) { |
| 45 ack_notifier->OnAck(sequence_number, delta_largest_observed); | 45 // If this has resulted in an empty AckNotifer, erase it. |
| 46 | |
| 47 // If this has resulted in an empty AckNotifer, erase it. | |
| 48 if (!ack_notifier->HasUnackedPackets()) { | |
| 49 delete ack_notifier; | 46 delete ack_notifier; |
| 50 } | 47 } |
| 51 } | 48 } |
| 52 | 49 |
| 53 // Remove the sequence number from the map as we have notified all the | 50 // Remove the sequence number from the map as we have notified all the |
| 54 // registered AckNotifiers, and we won't see it again. | 51 // registered AckNotifiers, and we won't see it again. |
| 55 ack_notifier_map_.erase(map_it); | 52 ack_notifier_map_.erase(map_it); |
| 56 } | 53 } |
| 57 | 54 |
| 58 void AckNotifierManager::OnPacketRetransmitted( | 55 void AckNotifierManager::OnPacketRetransmitted( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 | 70 |
| 74 // The old sequence number is no longer of interest, copy the updated | 71 // The old sequence number is no longer of interest, copy the updated |
| 75 // AckNotifiers to the new sequence number before deleting the old. | 72 // AckNotifiers to the new sequence number before deleting the old. |
| 76 ack_notifier_map_[new_sequence_number] = ack_notifier_list; | 73 ack_notifier_map_[new_sequence_number] = ack_notifier_list; |
| 77 ack_notifier_map_.erase(map_it); | 74 ack_notifier_map_.erase(map_it); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void AckNotifierManager::OnSerializedPacket( | 77 void AckNotifierManager::OnSerializedPacket( |
| 81 const SerializedPacket& serialized_packet) { | 78 const SerializedPacket& serialized_packet) { |
| 82 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | 79 if (FLAGS_quic_attach_ack_notifiers_to_packets) { |
| 83 // Inform each attached AckNotifier of the packet's sequence number. | 80 // Inform each attached AckNotifier of the packet's serialization. |
| 81 AckNotifierList& notifier_list = |
| 82 ack_notifier_map_[serialized_packet.sequence_number]; |
| 84 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { | 83 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { |
| 85 if (notifier == nullptr) { | 84 if (notifier == nullptr) { |
| 86 LOG(DFATAL) << "AckNotifier should not be nullptr."; | 85 LOG(DFATAL) << "AckNotifier should not be nullptr."; |
| 87 continue; | 86 continue; |
| 88 } | 87 } |
| 89 notifier->OnSerializedPacket(); | 88 notifier->OnSerializedPacket(); |
| 90 | 89 |
| 91 // Update the mapping in the other direction, from sequence number to | 90 // Update the mapping in the other direction, from sequence number to |
| 92 // AckNotifier. | 91 // AckNotifier. |
| 93 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); | 92 notifier_list.push_back(notifier); |
| 94 } | 93 } |
| 95 } else { | 94 } else { |
| 96 // AckNotifiers can only be attached to retransmittable frames. | 95 // AckNotifiers can only be attached to retransmittable frames. |
| 97 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; | 96 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; |
| 98 if (frames == nullptr) { | 97 if (frames == nullptr) { |
| 99 return; | 98 return; |
| 100 } | 99 } |
| 101 | 100 |
| 102 // For each frame in |serialized_packet|, inform any attached AckNotifiers | 101 // For each frame in |serialized_packet|, inform any attached AckNotifiers |
| 103 // of the packet's sequence number. | 102 // of the packet's sequence number. |
| 104 for (const QuicFrame& quic_frame : frames->frames()) { | 103 for (const QuicFrame& quic_frame : frames->frames()) { |
| 105 if (quic_frame.type != STREAM_FRAME || | 104 if (quic_frame.type != STREAM_FRAME || |
| 106 quic_frame.stream_frame->notifier == nullptr) { | 105 quic_frame.stream_frame->notifier == nullptr) { |
| 107 continue; | 106 continue; |
| 108 } | 107 } |
| 109 | 108 |
| 110 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier; | 109 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier; |
| 111 notifier->OnSerializedPacket(); | 110 notifier->OnSerializedPacket(); |
| 112 | 111 |
| 113 // Update the mapping in the other direction, from sequence number to | 112 // Update the mapping in the other direction, from sequence number to |
| 114 // AckNotifier. | 113 // AckNotifier. |
| 115 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); | 114 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 } | 117 } |
| 119 | 118 |
| 120 } // namespace net | 119 } // namespace net |
| OLD | NEW |