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

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

Issue 18307003: Implement the variable length changes necessary to easily accommodate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merging with TOT Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_packet_creator.h ('k') | net/quic/quic_packet_creator_test.cc » ('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/logging.h" 7 #include "base/logging.h"
8 #include "net/quic/crypto/quic_random.h" 8 #include "net/quic/crypto/quic_random.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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 packet_size_ -= kQuicVersionSize; 76 packet_size_ -= kQuicVersionSize;
77 } 77 }
78 } 78 }
79 79
80 bool QuicPacketCreator::HasRoomForStreamFrame() const { 80 bool QuicPacketCreator::HasRoomForStreamFrame() const {
81 return BytesFree() > QuicFramer::GetMinStreamFrameSize(); 81 return BytesFree() > QuicFramer::GetMinStreamFrameSize();
82 } 82 }
83 83
84 // static 84 // static
85 size_t QuicPacketCreator::StreamFramePacketOverhead( 85 size_t QuicPacketCreator::StreamFramePacketOverhead(
86 int num_frames,
87 QuicGuidLength guid_length, 86 QuicGuidLength guid_length,
88 bool include_version, 87 bool include_version,
89 QuicSequenceNumberLength sequence_number_length, 88 QuicSequenceNumberLength sequence_number_length,
90 InFecGroup is_in_fec_group) { 89 InFecGroup is_in_fec_group) {
91 return GetPacketHeaderSize(guid_length, include_version, 90 return GetPacketHeaderSize(guid_length, include_version,
92 sequence_number_length, is_in_fec_group) + 91 sequence_number_length, is_in_fec_group) +
93 QuicFramer::GetMinStreamFrameSize() * num_frames; 92 // Assumes this is a stream with a single lone packet.
93 QuicFramer::GetMinStreamFrameSize(1, 0, true);
94 } 94 }
95 95
96 size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, 96 size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id,
97 StringPiece data, 97 StringPiece data,
98 QuicStreamOffset offset, 98 QuicStreamOffset offset,
99 bool fin, 99 bool fin,
100 QuicFrame* frame) { 100 QuicFrame* frame) {
101 DCHECK_GT(options_.max_packet_length, 101 DCHECK_GT(options_.max_packet_length,
102 StreamFramePacketOverhead( 102 StreamFramePacketOverhead(
103 1, PACKET_8BYTE_GUID, kIncludeVersion, 103 PACKET_8BYTE_GUID, kIncludeVersion,
104 PACKET_6BYTE_SEQUENCE_NUMBER, IN_FEC_GROUP)); 104 PACKET_6BYTE_SEQUENCE_NUMBER, IN_FEC_GROUP));
105 DCHECK(HasRoomForStreamFrame()); 105 DCHECK(HasRoomForStreamFrame());
106 106
107 const size_t free_bytes = BytesFree(); 107 const size_t free_bytes = BytesFree();
108 size_t bytes_consumed = 0; 108 size_t bytes_consumed = 0;
109 109
110 if (data.size() != 0) { 110 if (data.size() != 0) {
111 size_t max_data_len = free_bytes - QuicFramer::GetMinStreamFrameSize(); 111 size_t min_last_stream_frame_size =
112 bytes_consumed = min<size_t>(max_data_len, data.size()); 112 QuicFramer::GetMinStreamFrameSize(id, offset, true);
113 // Comparing against the last stream frame size including the length
114 // guarantees that all the bytes will fit. Otherwise there is a
115 // discontinuity where the packet goes one byte over due to the length data.
116 if (data.size() > free_bytes - min_last_stream_frame_size -
117 kQuicStreamPayloadLengthSize) {
118 // Its the last frame, put as much data as possible in.
119 bytes_consumed =
120 min<size_t>(free_bytes - min_last_stream_frame_size, data.size());
121 } else {
122 bytes_consumed = data.size();
123 }
113 124
114 bool set_fin = fin && bytes_consumed == data.size(); // Last frame. 125 bool set_fin = fin && bytes_consumed == data.size(); // Last frame.
115 StringPiece data_frame(data.data(), bytes_consumed); 126 StringPiece data_frame(data.data(), bytes_consumed);
116 *frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, data_frame)); 127 *frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, data_frame));
117 } else { 128 } else {
118 DCHECK(fin); 129 DCHECK(fin);
119 // Create a new packet for the fin, if necessary. 130 // Create a new packet for the fin, if necessary.
120 *frame = QuicFrame(new QuicStreamFrame(id, true, offset, "")); 131 *frame = QuicFrame(new QuicStreamFrame(id, true, offset, ""));
121 } 132 }
122 133
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 queued_frames_.push_back( 280 queued_frames_.push_back(
270 queued_retransmittable_frames_->AddNonStreamFrame(frame)); 281 queued_retransmittable_frames_->AddNonStreamFrame(frame));
271 } 282 }
272 } else { 283 } else {
273 queued_frames_.push_back(frame); 284 queued_frames_.push_back(frame);
274 } 285 }
275 return true; 286 return true;
276 } 287 }
277 288
278 } // namespace net 289 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.h ('k') | net/quic/quic_packet_creator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698