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_ack_notifier.h" | 9 #include "net/quic/quic_ack_notifier.h" |
10 #include "net/quic/quic_fec_group.h" | 10 #include "net/quic/quic_fec_group.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, | 170 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, |
171 has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) { | 171 has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) { |
172 QuicFrame frame; | 172 QuicFrame frame; |
173 size_t bytes_consumed = packet_creator_.CreateStreamFrame( | 173 size_t bytes_consumed = packet_creator_.CreateStreamFrame( |
174 id, data, offset + total_bytes_consumed, fin, &frame); | 174 id, data, offset + total_bytes_consumed, fin, &frame); |
175 ++frames_created; | 175 ++frames_created; |
176 | 176 |
177 // We want to track which packet this stream frame ends up in. | 177 // We want to track which packet this stream frame ends up in. |
178 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | 178 if (FLAGS_quic_attach_ack_notifiers_to_packets) { |
179 if (notifier != nullptr) { | 179 if (notifier != nullptr) { |
180 ack_notifiers_.insert(notifier); | 180 ack_notifiers_.push_back(notifier); |
181 } | 181 } |
182 } else { | 182 } else { |
183 frame.stream_frame->notifier = notifier; | 183 frame.stream_frame->notifier = notifier; |
184 } | 184 } |
185 | 185 |
186 if (!AddFrame(frame)) { | 186 if (!AddFrame(frame)) { |
187 LOG(DFATAL) << "Failed to add stream frame."; | 187 LOG(DFATAL) << "Failed to add stream frame."; |
188 // Inability to add a STREAM frame creates an unrecoverable hole in a | 188 // Inability to add a STREAM frame creates an unrecoverable hole in a |
189 // the stream, so it's best to close the connection. | 189 // the stream, so it's best to close the connection. |
190 delegate_->CloseConnection(QUIC_INTERNAL_ERROR, false); | 190 delegate_->CloseConnection(QUIC_INTERNAL_ERROR, false); |
(...skipping 29 matching lines...) Expand all Loading... |
220 delete notifier; | 220 delete notifier; |
221 } | 221 } |
222 | 222 |
223 // Don't allow the handshake to be bundled with other retransmittable frames. | 223 // Don't allow the handshake to be bundled with other retransmittable frames. |
224 if (has_handshake) { | 224 if (has_handshake) { |
225 SendQueuedFrames(true); | 225 SendQueuedFrames(true); |
226 } | 226 } |
227 | 227 |
228 // Try to close FEC group since we've either run out of data to send or we're | 228 // Try to close FEC group since we've either run out of data to send or we're |
229 // blocked. If not in batch mode, force close the group. | 229 // blocked. If not in batch mode, force close the group. |
230 MaybeSendFecPacketAndCloseGroup(/*flush=*/false); | 230 MaybeSendFecPacketAndCloseGroup(/*force=*/false); |
231 | 231 |
232 DCHECK(InBatchMode() || !packet_creator_.HasPendingFrames()); | 232 DCHECK(InBatchMode() || !packet_creator_.HasPendingFrames()); |
233 return QuicConsumedData(total_bytes_consumed, fin_consumed); | 233 return QuicConsumedData(total_bytes_consumed, fin_consumed); |
234 } | 234 } |
235 | 235 |
236 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { | 236 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { |
237 DCHECK(HasPendingFrames()); | 237 DCHECK(HasPendingFrames()); |
238 HasRetransmittableData retransmittable = | 238 HasRetransmittableData retransmittable = |
239 (should_send_ack_ || should_send_stop_waiting_) | 239 (should_send_ack_ || should_send_stop_waiting_) |
240 ? NO_RETRANSMITTABLE_DATA | 240 ? NO_RETRANSMITTABLE_DATA |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 310 |
311 void QuicPacketGenerator::OnFecTimeout() { | 311 void QuicPacketGenerator::OnFecTimeout() { |
312 DCHECK(!InBatchMode()); | 312 DCHECK(!InBatchMode()); |
313 if (!ShouldSendFecPacket(true)) { | 313 if (!ShouldSendFecPacket(true)) { |
314 LOG(DFATAL) << "No FEC packet to send on FEC timeout."; | 314 LOG(DFATAL) << "No FEC packet to send on FEC timeout."; |
315 return; | 315 return; |
316 } | 316 } |
317 // Flush out any pending frames in the generator and the creator, and then | 317 // Flush out any pending frames in the generator and the creator, and then |
318 // send out FEC packet. | 318 // send out FEC packet. |
319 SendQueuedFrames(true); | 319 SendQueuedFrames(true); |
320 MaybeSendFecPacketAndCloseGroup(/*flush=*/true); | 320 MaybeSendFecPacketAndCloseGroup(/*force=*/true); |
321 } | 321 } |
322 | 322 |
323 QuicTime::Delta QuicPacketGenerator::GetFecTimeout( | 323 QuicTime::Delta QuicPacketGenerator::GetFecTimeout( |
324 QuicPacketSequenceNumber sequence_number) { | 324 QuicPacketSequenceNumber sequence_number) { |
325 // Do not set up FEC alarm for |sequence_number| it is not the first packet in | 325 // Do not set up FEC alarm for |sequence_number| it is not the first packet in |
326 // the current group. | 326 // the current group. |
327 if (packet_creator_.IsFecGroupOpen() && | 327 if (packet_creator_.IsFecGroupOpen() && |
328 (sequence_number == packet_creator_.fec_group_number())) { | 328 (sequence_number == packet_creator_.fec_group_number())) { |
329 return QuicTime::Delta::Max( | 329 return QuicTime::Delta::Max( |
330 fec_timeout_, QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs)); | 330 fec_timeout_, QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 SerializedPacket serialized_packet = packet_creator_.SerializePacket(); | 400 SerializedPacket serialized_packet = packet_creator_.SerializePacket(); |
401 DCHECK(serialized_packet.packet); | 401 DCHECK(serialized_packet.packet); |
402 | 402 |
403 // There may be AckNotifiers interested in this packet. | 403 // There may be AckNotifiers interested in this packet. |
404 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | 404 if (FLAGS_quic_attach_ack_notifiers_to_packets) { |
405 serialized_packet.notifiers.swap(ack_notifiers_); | 405 serialized_packet.notifiers.swap(ack_notifiers_); |
406 ack_notifiers_.clear(); | 406 ack_notifiers_.clear(); |
407 } | 407 } |
408 | 408 |
409 delegate_->OnSerializedPacket(serialized_packet); | 409 delegate_->OnSerializedPacket(serialized_packet); |
410 MaybeSendFecPacketAndCloseGroup(/*flush=*/false); | 410 MaybeSendFecPacketAndCloseGroup(/*force=*/false); |
411 | 411 |
412 // The packet has now been serialized, safe to delete pending frames. | 412 // The packet has now been serialized, safe to delete pending frames. |
413 pending_ack_frame_.reset(); | 413 pending_ack_frame_.reset(); |
414 pending_stop_waiting_frame_.reset(); | 414 pending_stop_waiting_frame_.reset(); |
415 } | 415 } |
416 | 416 |
417 void QuicPacketGenerator::StopSendingVersion() { | 417 void QuicPacketGenerator::StopSendingVersion() { |
418 packet_creator_.StopSendingVersion(); | 418 packet_creator_.StopSendingVersion(); |
419 } | 419 } |
420 | 420 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 packet_creator_.set_connection_id_length(PACKET_8BYTE_CONNECTION_ID); | 459 packet_creator_.set_connection_id_length(PACKET_8BYTE_CONNECTION_ID); |
460 } | 460 } |
461 } | 461 } |
462 | 462 |
463 | 463 |
464 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { | 464 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { |
465 packet_creator_.set_encryption_level(level); | 465 packet_creator_.set_encryption_level(level); |
466 } | 466 } |
467 | 467 |
468 } // namespace net | 468 } // namespace net |
OLD | NEW |