OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_packet_generator.h" | 5 #include "net/quic/quic_packet_generator.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/quic/quic_fec_group.h" | 9 #include "net/quic/quic_fec_group.h" |
10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 debug_delegate_(debug_delegate), | 22 debug_delegate_(debug_delegate), |
23 packet_creator_(creator), | 23 packet_creator_(creator), |
24 batch_mode_(false), | 24 batch_mode_(false), |
25 should_send_ack_(false), | 25 should_send_ack_(false), |
26 should_send_feedback_(false), | 26 should_send_feedback_(false), |
27 should_send_stop_waiting_(false) { | 27 should_send_stop_waiting_(false) { |
28 } | 28 } |
29 | 29 |
30 QuicPacketGenerator::~QuicPacketGenerator() { | 30 QuicPacketGenerator::~QuicPacketGenerator() { |
31 for (QuicFrames::iterator it = queued_control_frames_.begin(); | 31 for (QuicFrames::iterator it = queued_control_frames_.begin(); |
32 it != queued_control_frames_.end(); ++it) { | 32 it != queued_control_frames_.end(); |
| 33 ++it) { |
33 switch (it->type) { | 34 switch (it->type) { |
34 case PADDING_FRAME: | 35 case PADDING_FRAME: |
35 delete it->padding_frame; | 36 delete it->padding_frame; |
36 break; | 37 break; |
37 case STREAM_FRAME: | 38 case STREAM_FRAME: |
38 delete it->stream_frame; | 39 delete it->stream_frame; |
39 break; | 40 break; |
40 case ACK_FRAME: | 41 case ACK_FRAME: |
41 delete it->ack_frame; | 42 delete it->ack_frame; |
42 break; | 43 break; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 99 |
99 size_t total_bytes_consumed = 0; | 100 size_t total_bytes_consumed = 0; |
100 bool fin_consumed = false; | 101 bool fin_consumed = false; |
101 | 102 |
102 if (!packet_creator_->HasRoomForStreamFrame(id, offset)) { | 103 if (!packet_creator_->HasRoomForStreamFrame(id, offset)) { |
103 SerializeAndSendPacket(); | 104 SerializeAndSendPacket(); |
104 } | 105 } |
105 | 106 |
106 IOVector data = data_to_write; | 107 IOVector data = data_to_write; |
107 size_t data_size = data.TotalBufferSize(); | 108 size_t data_size = data.TotalBufferSize(); |
108 while (delegate_->ShouldGeneratePacket(NOT_RETRANSMISSION, | 109 while (delegate_->ShouldGeneratePacket( |
109 HAS_RETRANSMITTABLE_DATA, handshake)) { | 110 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, handshake)) { |
110 QuicFrame frame; | 111 QuicFrame frame; |
111 size_t bytes_consumed; | 112 size_t bytes_consumed; |
112 if (notifier != NULL) { | 113 if (notifier != NULL) { |
113 // We want to track which packet this stream frame ends up in. | 114 // We want to track which packet this stream frame ends up in. |
114 bytes_consumed = packet_creator_->CreateStreamFrameWithNotifier( | 115 bytes_consumed = packet_creator_->CreateStreamFrameWithNotifier( |
115 id, data, offset + total_bytes_consumed, fin, notifier, &frame); | 116 id, data, offset + total_bytes_consumed, fin, notifier, &frame); |
116 } else { | 117 } else { |
117 bytes_consumed = packet_creator_->CreateStreamFrame( | 118 bytes_consumed = packet_creator_->CreateStreamFrame( |
118 id, data, offset + total_bytes_consumed, fin, &frame); | 119 id, data, offset + total_bytes_consumed, fin, &frame); |
119 } | 120 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 155 } |
155 | 156 |
156 DCHECK(InBatchMode() || !packet_creator_->HasPendingFrames()); | 157 DCHECK(InBatchMode() || !packet_creator_->HasPendingFrames()); |
157 return QuicConsumedData(total_bytes_consumed, fin_consumed); | 158 return QuicConsumedData(total_bytes_consumed, fin_consumed); |
158 } | 159 } |
159 | 160 |
160 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { | 161 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { |
161 DCHECK(HasPendingFrames()); | 162 DCHECK(HasPendingFrames()); |
162 HasRetransmittableData retransmittable = | 163 HasRetransmittableData retransmittable = |
163 (should_send_ack_ || should_send_feedback_ || should_send_stop_waiting_) | 164 (should_send_ack_ || should_send_feedback_ || should_send_stop_waiting_) |
164 ? NO_RETRANSMITTABLE_DATA : HAS_RETRANSMITTABLE_DATA; | 165 ? NO_RETRANSMITTABLE_DATA |
| 166 : HAS_RETRANSMITTABLE_DATA; |
165 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { | 167 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { |
166 DCHECK(!queued_control_frames_.empty()); // These are retransmittable. | 168 DCHECK(!queued_control_frames_.empty()); // These are retransmittable. |
167 } | 169 } |
168 return delegate_->ShouldGeneratePacket(NOT_RETRANSMISSION, retransmittable, | 170 return delegate_->ShouldGeneratePacket( |
169 NOT_HANDSHAKE); | 171 NOT_RETRANSMISSION, retransmittable, NOT_HANDSHAKE); |
170 } | 172 } |
171 | 173 |
172 void QuicPacketGenerator::SendQueuedFrames(bool flush) { | 174 void QuicPacketGenerator::SendQueuedFrames(bool flush) { |
173 // Only add pending frames if we are SURE we can then send the whole packet. | 175 // Only add pending frames if we are SURE we can then send the whole packet. |
174 while (HasPendingFrames() && | 176 while (HasPendingFrames() && |
175 (flush || CanSendWithNextPendingFrameAddition())) { | 177 (flush || CanSendWithNextPendingFrameAddition())) { |
176 if (!AddNextPendingFrame()) { | 178 if (!AddNextPendingFrame()) { |
177 // Packet was full, so serialize and send it. | 179 // Packet was full, so serialize and send it. |
178 SerializeAndSendPacket(); | 180 SerializeAndSendPacket(); |
179 } | 181 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 void QuicPacketGenerator::FlushAllQueuedFrames() { | 215 void QuicPacketGenerator::FlushAllQueuedFrames() { |
214 SendQueuedFrames(true); | 216 SendQueuedFrames(true); |
215 } | 217 } |
216 | 218 |
217 bool QuicPacketGenerator::HasQueuedFrames() const { | 219 bool QuicPacketGenerator::HasQueuedFrames() const { |
218 return packet_creator_->HasPendingFrames() || HasPendingFrames(); | 220 return packet_creator_->HasPendingFrames() || HasPendingFrames(); |
219 } | 221 } |
220 | 222 |
221 bool QuicPacketGenerator::HasPendingFrames() const { | 223 bool QuicPacketGenerator::HasPendingFrames() const { |
222 return should_send_ack_ || should_send_feedback_ || | 224 return should_send_ack_ || should_send_feedback_ || |
223 should_send_stop_waiting_ || !queued_control_frames_.empty(); | 225 should_send_stop_waiting_ || !queued_control_frames_.empty(); |
224 } | 226 } |
225 | 227 |
226 bool QuicPacketGenerator::AddNextPendingFrame() { | 228 bool QuicPacketGenerator::AddNextPendingFrame() { |
227 if (should_send_ack_) { | 229 if (should_send_ack_) { |
228 pending_ack_frame_.reset(delegate_->CreateAckFrame()); | 230 pending_ack_frame_.reset(delegate_->CreateAckFrame()); |
229 // If we can't this add the frame now, then we still need to do so later. | 231 // If we can't this add the frame now, then we still need to do so later. |
230 should_send_ack_ = !AddFrame(QuicFrame(pending_ack_frame_.get())); | 232 should_send_ack_ = !AddFrame(QuicFrame(pending_ack_frame_.get())); |
231 // Return success if we have cleared out this flag (i.e., added the frame). | 233 // Return success if we have cleared out this flag (i.e., added the frame). |
232 // If we still need to send, then the frame is full, and we have failed. | 234 // If we still need to send, then the frame is full, and we have failed. |
233 return !should_send_ack_; | 235 return !should_send_ack_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (packet_creator_->ShouldSendFec(false)) { | 280 if (packet_creator_->ShouldSendFec(false)) { |
279 // TODO(jri): SerializeFec can return a NULL packet, and this should | 281 // TODO(jri): SerializeFec can return a NULL packet, and this should |
280 // cause an early return, with a call to delegate_->OnPacketGenerationError. | 282 // cause an early return, with a call to delegate_->OnPacketGenerationError. |
281 SerializedPacket serialized_fec = packet_creator_->SerializeFec(); | 283 SerializedPacket serialized_fec = packet_creator_->SerializeFec(); |
282 DCHECK(serialized_fec.packet); | 284 DCHECK(serialized_fec.packet); |
283 delegate_->OnSerializedPacket(serialized_fec); | 285 delegate_->OnSerializedPacket(serialized_fec); |
284 } | 286 } |
285 } | 287 } |
286 | 288 |
287 } // namespace net | 289 } // namespace net |
OLD | NEW |