Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: net/quic/quic_packet_creator.cc

Issue 932723002: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_framer_test.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_creator.h" 5 #include "net/quic/quic_packet_creator.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/crypto/quic_random.h" 9 #include "net/quic/crypto/quic_random.h"
10 #include "net/quic/quic_ack_notifier.h" 10 #include "net/quic/quic_ack_notifier.h"
11 #include "net/quic/quic_data_writer.h"
11 #include "net/quic/quic_fec_group.h" 12 #include "net/quic/quic_fec_group.h"
12 #include "net/quic/quic_utils.h" 13 #include "net/quic/quic_utils.h"
13 14
14 using base::StringPiece; 15 using base::StringPiece;
15 using std::make_pair; 16 using std::make_pair;
16 using std::max; 17 using std::max;
17 using std::min; 18 using std::min;
18 using std::pair; 19 using std::pair;
19 using std::vector; 20 using std::vector;
20 21
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 291
291 // TODO(ianswett): Remove this method, because it's test only. 292 // TODO(ianswett): Remove this method, because it's test only.
292 SerializedPacket QuicPacketCreator::SerializeAllFrames( 293 SerializedPacket QuicPacketCreator::SerializeAllFrames(
293 const QuicFrames& frames) { 294 const QuicFrames& frames) {
294 // TODO(satyamshekhar): Verify that this DCHECK won't fail. What about queued 295 // TODO(satyamshekhar): Verify that this DCHECK won't fail. What about queued
295 // frames from SendStreamData()[send_stream_should_flush_ == false && 296 // frames from SendStreamData()[send_stream_should_flush_ == false &&
296 // data.empty() == true] and retransmit due to RTO. 297 // data.empty() == true] and retransmit due to RTO.
297 DCHECK_EQ(0u, queued_frames_.size()); 298 DCHECK_EQ(0u, queued_frames_.size());
298 LOG_IF(DFATAL, frames.empty()) 299 LOG_IF(DFATAL, frames.empty())
299 << "Attempt to serialize empty packet"; 300 << "Attempt to serialize empty packet";
300 for (size_t i = 0; i < frames.size(); ++i) { 301 for (const QuicFrame& frame : frames) {
301 bool success = AddFrame(frames[i], false); 302 bool success = AddFrame(frame, false);
302 DCHECK(success); 303 DCHECK(success);
303 } 304 }
304 SerializedPacket packet = SerializePacket(); 305 SerializedPacket packet = SerializePacket();
305 DCHECK(packet.retransmittable_frames == nullptr); 306 DCHECK(packet.retransmittable_frames == nullptr);
306 return packet; 307 return packet;
307 } 308 }
308 309
309 bool QuicPacketCreator::HasPendingFrames() const { 310 bool QuicPacketCreator::HasPendingFrames() const {
310 return !queued_frames_.empty(); 311 return !queued_frames_.empty();
311 } 312 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 size_t max_plaintext_size = 366 size_t max_plaintext_size =
366 framer_->GetMaxPlaintextSize(max_packet_length_); 367 framer_->GetMaxPlaintextSize(max_packet_length_);
367 DCHECK_GE(max_plaintext_size, packet_size_); 368 DCHECK_GE(max_plaintext_size, packet_size_);
368 // ACK Frames will be truncated due to length only if they're the only frame 369 // ACK Frames will be truncated due to length only if they're the only frame
369 // in the packet, and if packet_size_ was set to max_plaintext_size. If 370 // in the packet, and if packet_size_ was set to max_plaintext_size. If
370 // truncation due to length occurred, then GetSerializedFrameLength will have 371 // truncation due to length occurred, then GetSerializedFrameLength will have
371 // returned all bytes free. 372 // returned all bytes free.
372 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size && 373 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size &&
373 queued_frames_.size() == 1 && 374 queued_frames_.size() == 1 &&
374 queued_frames_.back().type == ACK_FRAME; 375 queued_frames_.back().type == ACK_FRAME;
375 scoped_ptr<QuicPacket> packet( 376 char buffer[kMaxPacketSize];
376 framer_->BuildDataPacket(header, queued_frames_, packet_size_)); 377 scoped_ptr<QuicPacket> packet;
378 // Use the packet_size_ instead of the buffer size to ensure smaller
379 // packet sizes are properly used.
380 scoped_ptr<char[]> large_buffer;
381 if (packet_size_ <= kMaxPacketSize) {
382 packet.reset(
383 framer_->BuildDataPacket(header, queued_frames_, buffer, packet_size_));
384 } else {
385 large_buffer.reset(new char[packet_size_]);
386 packet.reset(framer_->BuildDataPacket(header, queued_frames_,
387 large_buffer.get(), packet_size_));
388 }
377 LOG_IF(DFATAL, packet == nullptr) << "Failed to serialize " 389 LOG_IF(DFATAL, packet == nullptr) << "Failed to serialize "
378 << queued_frames_.size() << " frames."; 390 << queued_frames_.size() << " frames.";
379 // Because of possible truncation, we can't be confident that our 391 // Because of possible truncation, we can't be confident that our
380 // packet size calculation worked correctly. 392 // packet size calculation worked correctly.
381 if (!possibly_truncated_by_length) { 393 if (!possibly_truncated_by_length) {
382 DCHECK_EQ(packet_size_, packet->length()); 394 DCHECK_EQ(packet_size_, packet->length());
383 } 395 }
384 // Immediately encrypt the packet, to ensure we don't encrypt the same packet 396 // Immediately encrypt the packet, to ensure we don't encrypt the same packet
385 // sequence number multiple times. 397 // sequence number multiple times.
386 QuicEncryptedPacket* encrypted = 398 QuicEncryptedPacket* encrypted =
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 if (!is_handshake) { 554 if (!is_handshake) {
543 return; 555 return;
544 } 556 }
545 557
546 QuicPaddingFrame padding; 558 QuicPaddingFrame padding;
547 bool success = AddFrame(QuicFrame(&padding), false); 559 bool success = AddFrame(QuicFrame(&padding), false);
548 DCHECK(success); 560 DCHECK(success);
549 } 561 }
550 562
551 } // namespace net 563 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer_test.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698