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_creator.h" | 5 #include "net/quic/quic_packet_creator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ && | 493 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ && |
494 queued_frames_.size() == 1 && | 494 queued_frames_.size() == 1 && |
495 queued_frames_.back().type == ACK_FRAME; | 495 queued_frames_.back().type == ACK_FRAME; |
496 // The optimized encryption algorithm implementations run faster when | 496 // The optimized encryption algorithm implementations run faster when |
497 // operating on aligned memory. | 497 // operating on aligned memory. |
498 // TODO(rtenneti): Change the default 64 alignas value (used the default | 498 // TODO(rtenneti): Change the default 64 alignas value (used the default |
499 // value from CACHELINE_SIZE). | 499 // value from CACHELINE_SIZE). |
500 ALIGNAS(64) char buffer[kMaxPacketSize]; | 500 ALIGNAS(64) char buffer[kMaxPacketSize]; |
501 // Use the packet_size_ instead of the buffer size to ensure smaller | 501 // Use the packet_size_ instead of the buffer size to ensure smaller |
502 // packet sizes are properly used. | 502 // packet sizes are properly used. |
503 scoped_ptr<char[]> large_buffer; | 503 size_t length = |
504 size_t length = 0; | 504 framer_->BuildDataPacket(header, queued_frames_, buffer, packet_size_); |
505 const bool use_stack_buffer = packet_size_ <= kMaxPacketSize; | |
506 if (use_stack_buffer) { | |
507 length = | |
508 framer_->BuildDataPacket(header, queued_frames_, buffer, packet_size_); | |
509 } else { | |
510 large_buffer.reset(new char[packet_size_]); | |
511 length = framer_->BuildDataPacket(header, queued_frames_, | |
512 large_buffer.get(), packet_size_); | |
513 } | |
514 if (length == 0) { | 505 if (length == 0) { |
515 LOG(DFATAL) << "Failed to serialize " << queued_frames_.size() | 506 LOG(DFATAL) << "Failed to serialize " << queued_frames_.size() |
516 << " frames."; | 507 << " frames."; |
517 return NoPacket(); | 508 return NoPacket(); |
518 } | 509 } |
519 | 510 |
520 // TODO(ianswett) Consider replacing QuicPacket with something else, | 511 // TODO(ianswett) Consider replacing QuicPacket with something else, |
521 // since it's only used to provide convenience methods to FEC and encryption. | 512 // since it's only used to provide convenience methods to FEC and encryption. |
522 QuicPacket packet(use_stack_buffer ? buffer : large_buffer.get(), length, | 513 QuicPacket packet(buffer, length, |
523 /* owns_buffer */ false, | 514 /* owns_buffer */ false, |
524 header.public_header.connection_id_length, | 515 header.public_header.connection_id_length, |
525 header.public_header.version_flag, | 516 header.public_header.version_flag, |
526 header.public_header.packet_number_length); | 517 header.public_header.packet_number_length); |
527 OnBuiltFecProtectedPayload(header, packet.FecProtectedData()); | 518 OnBuiltFecProtectedPayload(header, packet.FecProtectedData()); |
528 | 519 |
529 // Because of possible truncation, we can't be confident that our | 520 // Because of possible truncation, we can't be confident that our |
530 // packet size calculation worked correctly. | 521 // packet size calculation worked correctly. |
531 if (!possibly_truncated_by_length) { | 522 if (!possibly_truncated_by_length) { |
532 DCHECK_EQ(packet_size_, length); | 523 DCHECK_EQ(packet_size_, length); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 if (BytesFree() == 0) { | 680 if (BytesFree() == 0) { |
690 // Don't pad full packets. | 681 // Don't pad full packets. |
691 return; | 682 return; |
692 } | 683 } |
693 | 684 |
694 bool success = AddFrame(QuicFrame(QuicPaddingFrame()), false, false, nullptr); | 685 bool success = AddFrame(QuicFrame(QuicPaddingFrame()), false, false, nullptr); |
695 DCHECK(success); | 686 DCHECK(success); |
696 } | 687 } |
697 | 688 |
698 } // namespace net | 689 } // namespace net |
OLD | NEW |