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

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

Issue 1464153002: Add ConsumeData method to QuicPacketCreator, ConsumeData wraps both CreateStreamFrame and AddFrame.… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@107699435
Patch Set: Created 5 years, 1 month 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_packet_creator_test.cc ('k') | net/quic/test_tools/quic_packet_creator_peer.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_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_flags.h" 10 #include "net/quic/quic_flags.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 if (fec_protection == MUST_FEC_PROTECT) { 145 if (fec_protection == MUST_FEC_PROTECT) {
146 MaybeStartFecProtection(); 146 MaybeStartFecProtection();
147 } 147 }
148 148
149 if (!fin && (iov.total_length == 0)) { 149 if (!fin && (iov.total_length == 0)) {
150 LOG(DFATAL) << "Attempt to consume empty data without FIN."; 150 LOG(DFATAL) << "Attempt to consume empty data without FIN.";
151 return QuicConsumedData(0, false); 151 return QuicConsumedData(0, false);
152 } 152 }
153 153
154 int frames_created = 0;
155 while (delegate_->ShouldGeneratePacket( 154 while (delegate_->ShouldGeneratePacket(
156 HAS_RETRANSMITTABLE_DATA, has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) { 155 HAS_RETRANSMITTABLE_DATA, has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) {
157 QuicFrame frame; 156 QuicFrame frame;
158 UniqueStreamBuffer buffer; 157 if (!packet_creator_.ConsumeData(id, iov, total_bytes_consumed,
159 size_t bytes_consumed = packet_creator_.CreateStreamFrame( 158 offset + total_bytes_consumed, fin,
160 id, iov, total_bytes_consumed, offset + total_bytes_consumed, fin, 159 has_handshake, &frame)) {
161 &frame, &buffer); 160 LOG(DFATAL) << "Created but failed to add a stream frame.";
162 ++frames_created;
163
164 if (!AddFrame(frame, buffer.Pass(), has_handshake)) {
165 LOG(DFATAL) << "Failed to add stream frame.";
166 // Inability to add a STREAM frame creates an unrecoverable hole in a 161 // Inability to add a STREAM frame creates an unrecoverable hole in a
167 // the stream, so it's best to close the connection. 162 // the stream, so it's best to close the connection.
168 delegate_->CloseConnection(QUIC_INTERNAL_ERROR, false); 163 delegate_->CloseConnection(QUIC_INTERNAL_ERROR, false);
169 return QuicConsumedData(0, false); 164 return QuicConsumedData(0, false);
170 } 165 }
166 DCHECK(frame.stream_frame);
167 size_t bytes_consumed = frame.stream_frame->data.length();
168 if (debug_delegate_ != nullptr) {
169 debug_delegate_->OnFrameAddedToPacket(frame);
170 }
171
171 if (listener != nullptr) { 172 if (listener != nullptr) {
172 ack_listeners_.push_back(AckListenerWrapper(listener, bytes_consumed)); 173 ack_listeners_.push_back(AckListenerWrapper(listener, bytes_consumed));
173 } 174 }
174 175
175 total_bytes_consumed += bytes_consumed; 176 total_bytes_consumed += bytes_consumed;
176 fin_consumed = fin && total_bytes_consumed == iov.total_length; 177 fin_consumed = fin && total_bytes_consumed == iov.total_length;
177 DCHECK(total_bytes_consumed == iov.total_length || 178 DCHECK(total_bytes_consumed == iov.total_length ||
178 packet_creator_.BytesFree() == 0u); 179 packet_creator_.BytesFree() == 0u);
179 180
180 if (!InBatchMode() || !packet_creator_.HasRoomForStreamFrame(id, offset)) { 181 if (!InBatchMode() || !packet_creator_.HasRoomForStreamFrame(id, offset)) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { 527 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) {
527 packet_creator_.set_encryption_level(level); 528 packet_creator_.set_encryption_level(level);
528 } 529 }
529 530
530 void QuicPacketGenerator::SetEncrypter(EncryptionLevel level, 531 void QuicPacketGenerator::SetEncrypter(EncryptionLevel level,
531 QuicEncrypter* encrypter) { 532 QuicEncrypter* encrypter) {
532 packet_creator_.SetEncrypter(level, encrypter); 533 packet_creator_.SetEncrypter(level, encrypter);
533 } 534 }
534 535
535 } // namespace net 536 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator_test.cc ('k') | net/quic/test_tools/quic_packet_creator_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698