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

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

Issue 306013009: Remove the TransmissionType argument from QuicConnection CanWrite and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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_connection.h ('k') | net/quic/quic_reliable_client_stream.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_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 942 }
943 943
944 void QuicConnection::MaybeSendInResponseToPacket() { 944 void QuicConnection::MaybeSendInResponseToPacket() {
945 if (!connected_) { 945 if (!connected_) {
946 return; 946 return;
947 } 947 }
948 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); 948 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK);
949 949
950 // Now that we have received an ack, we might be able to send packets which 950 // Now that we have received an ack, we might be able to send packets which
951 // are queued locally, or drain streams which are blocked. 951 // are queued locally, or drain streams which are blocked.
952 if (CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)) { 952 if (CanWrite(HAS_RETRANSMITTABLE_DATA)) {
953 OnCanWrite(); 953 OnCanWrite();
954 } 954 }
955 } 955 }
956 956
957 void QuicConnection::SendVersionNegotiationPacket() { 957 void QuicConnection::SendVersionNegotiationPacket() {
958 // TODO(alyssar): implement zero server state negotiation. 958 // TODO(alyssar): implement zero server state negotiation.
959 pending_version_negotiation_packet_ = true; 959 pending_version_negotiation_packet_ = true;
960 if (writer_->IsWriteBlocked()) { 960 if (writer_->IsWriteBlocked()) {
961 visitor_->OnWriteBlocked(); 961 visitor_->OnWriteBlocked();
962 return; 962 return;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 void QuicConnection::OnCanWrite() { 1131 void QuicConnection::OnCanWrite() {
1132 DCHECK(!writer_->IsWriteBlocked()); 1132 DCHECK(!writer_->IsWriteBlocked());
1133 1133
1134 WriteQueuedPackets(); 1134 WriteQueuedPackets();
1135 WritePendingRetransmissions(); 1135 WritePendingRetransmissions();
1136 1136
1137 // Sending queued packets may have caused the socket to become write blocked, 1137 // Sending queued packets may have caused the socket to become write blocked,
1138 // or the congestion manager to prohibit sending. If we've sent everything 1138 // or the congestion manager to prohibit sending. If we've sent everything
1139 // we had queued and we're still not blocked, let the visitor know it can 1139 // we had queued and we're still not blocked, let the visitor know it can
1140 // write more. 1140 // write more.
1141 if (!CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)) { 1141 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1142 return; 1142 return;
1143 } 1143 }
1144 1144
1145 { // Limit the scope of the bundler. 1145 { // Limit the scope of the bundler.
1146 // Set |include_ack| to false in bundler; ack inclusion happens elsewhere. 1146 // Set |include_ack| to false in bundler; ack inclusion happens elsewhere.
1147 ScopedPacketBundler bundler(this, NO_ACK); 1147 ScopedPacketBundler bundler(this, NO_ACK);
1148 visitor_->OnCanWrite(); 1148 visitor_->OnCanWrite();
1149 } 1149 }
1150 1150
1151 // After the visitor writes, it may have caused the socket to become write 1151 // After the visitor writes, it may have caused the socket to become write
1152 // blocked or the congestion manager to prohibit sending, so check again. 1152 // blocked or the congestion manager to prohibit sending, so check again.
1153 if (visitor_->WillingAndAbleToWrite() && 1153 if (visitor_->WillingAndAbleToWrite() &&
1154 !resume_writes_alarm_->IsSet() && 1154 !resume_writes_alarm_->IsSet() &&
1155 CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)) { 1155 CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1156 // We're not write blocked, but some stream didn't write out all of its 1156 // We're not write blocked, but some stream didn't write out all of its
1157 // bytes. Register for 'immediate' resumption so we'll keep writing after 1157 // bytes. Register for 'immediate' resumption so we'll keep writing after
1158 // other connections and events have had a chance to use the thread. 1158 // other connections and events have had a chance to use the thread.
1159 resume_writes_alarm_->Set(clock_->ApproximateNow()); 1159 resume_writes_alarm_->Set(clock_->ApproximateNow());
1160 } 1160 }
1161 } 1161 }
1162 1162
1163 void QuicConnection::WriteIfNotBlocked() { 1163 void QuicConnection::WriteIfNotBlocked() {
1164 if (!writer_->IsWriteBlocked()) { 1164 if (!writer_->IsWriteBlocked()) {
1165 OnCanWrite(); 1165 OnCanWrite();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1216 }
1217 } 1217 }
1218 1218
1219 void QuicConnection::WritePendingRetransmissions() { 1219 void QuicConnection::WritePendingRetransmissions() {
1220 // Keep writing as long as there's a pending retransmission which can be 1220 // Keep writing as long as there's a pending retransmission which can be
1221 // written. 1221 // written.
1222 while (sent_packet_manager_.HasPendingRetransmissions()) { 1222 while (sent_packet_manager_.HasPendingRetransmissions()) {
1223 const QuicSentPacketManager::PendingRetransmission pending = 1223 const QuicSentPacketManager::PendingRetransmission pending =
1224 sent_packet_manager_.NextPendingRetransmission(); 1224 sent_packet_manager_.NextPendingRetransmission();
1225 if (GetPacketType(&pending.retransmittable_frames) == NORMAL && 1225 if (GetPacketType(&pending.retransmittable_frames) == NORMAL &&
1226 !CanWrite(pending.transmission_type, HAS_RETRANSMITTABLE_DATA)) { 1226 !CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1227 break; 1227 break;
1228 } 1228 }
1229 1229
1230 // Re-packetize the frames with a new sequence number for retransmission. 1230 // Re-packetize the frames with a new sequence number for retransmission.
1231 // Retransmitted data packets do not use FEC, even when it's enabled. 1231 // Retransmitted data packets do not use FEC, even when it's enabled.
1232 // Retransmitted packets use the same sequence number length as the 1232 // Retransmitted packets use the same sequence number length as the
1233 // original. 1233 // original.
1234 // Flush the packet creator before making a new packet. 1234 // Flush the packet creator before making a new packet.
1235 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that 1235 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that
1236 // does not require the creator to be flushed. 1236 // does not require the creator to be flushed.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 bool QuicConnection::ShouldGeneratePacket( 1274 bool QuicConnection::ShouldGeneratePacket(
1275 TransmissionType transmission_type, 1275 TransmissionType transmission_type,
1276 HasRetransmittableData retransmittable, 1276 HasRetransmittableData retransmittable,
1277 IsHandshake handshake) { 1277 IsHandshake handshake) {
1278 // We should serialize handshake packets immediately to ensure that they 1278 // We should serialize handshake packets immediately to ensure that they
1279 // end up sent at the right encryption level. 1279 // end up sent at the right encryption level.
1280 if (handshake == IS_HANDSHAKE) { 1280 if (handshake == IS_HANDSHAKE) {
1281 return true; 1281 return true;
1282 } 1282 }
1283 1283
1284 return CanWrite(transmission_type, retransmittable); 1284 return CanWrite(retransmittable);
1285 } 1285 }
1286 1286
1287 bool QuicConnection::CanWrite(TransmissionType transmission_type, 1287 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) {
1288 HasRetransmittableData retransmittable) {
1289 if (writer_->IsWriteBlocked()) { 1288 if (writer_->IsWriteBlocked()) {
1290 visitor_->OnWriteBlocked(); 1289 visitor_->OnWriteBlocked();
1291 return false; 1290 return false;
1292 } 1291 }
1293 1292
1294 send_alarm_->Cancel(); 1293 send_alarm_->Cancel();
1295 QuicTime now = clock_->Now(); 1294 QuicTime now = clock_->Now();
1296 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( 1295 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend(
1297 now, transmission_type, retransmittable); 1296 now, retransmittable);
1298 if (delay.IsInfinite()) { 1297 if (delay.IsInfinite()) {
1299 return false; 1298 return false;
1300 } 1299 }
1301 1300
1302 // If the scheduler requires a delay, then we can not send this packet now. 1301 // If the scheduler requires a delay, then we can not send this packet now.
1303 if (!delay.IsZero()) { 1302 if (!delay.IsZero()) {
1304 send_alarm_->Set(now.Add(delay)); 1303 send_alarm_->Set(now.Add(delay));
1305 DVLOG(1) << "Delaying sending."; 1304 DVLOG(1) << "Delaying sending.";
1306 return false; 1305 return false;
1307 } 1306 }
1308 return true; 1307 return true;
1309 } 1308 }
1310 1309
1311 bool QuicConnection::WritePacket(QueuedPacket packet) { 1310 bool QuicConnection::WritePacket(QueuedPacket packet) {
1312 QuicPacketSequenceNumber sequence_number = packet.sequence_number; 1311 QuicPacketSequenceNumber sequence_number = packet.sequence_number;
1313 if (ShouldDiscardPacket(packet.encryption_level, 1312 if (ShouldDiscardPacket(packet.encryption_level,
1314 sequence_number, 1313 sequence_number,
1315 packet.retransmittable)) { 1314 packet.retransmittable)) {
1316 ++stats_.packets_discarded; 1315 ++stats_.packets_discarded;
1317 return true; 1316 return true;
1318 } 1317 }
1319 1318
1320 // If the packet is CONNECTION_CLOSE, we need to try to send it immediately 1319 // If the packet is CONNECTION_CLOSE, we need to try to send it immediately
1321 // and encrypt it to hand it off to TimeWaitListManager. 1320 // and encrypt it to hand it off to TimeWaitListManager.
1322 // If the packet is QUEUED, we don't re-consult the congestion control. 1321 // If the packet is QUEUED, we don't re-consult the congestion control.
1323 // This ensures packets are sent in sequence number order. 1322 // This ensures packets are sent in sequence number order.
1324 // TODO(ianswett): The congestion control should have been consulted before 1323 // TODO(ianswett): The congestion control should have been consulted before
1325 // serializing the packet, so this could be turned into a LOG_IF(DFATAL). 1324 // serializing the packet, so this could be turned into a LOG_IF(DFATAL).
1326 if (packet.type == NORMAL && !CanWrite(packet.transmission_type, 1325 if (packet.type == NORMAL && !CanWrite(packet.retransmittable)) {
1327 packet.retransmittable)) {
1328 return false; 1326 return false;
1329 } 1327 }
1330 1328
1331 // Some encryption algorithms require the packet sequence numbers not be 1329 // Some encryption algorithms require the packet sequence numbers not be
1332 // repeated. 1330 // repeated.
1333 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); 1331 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number);
1334 sequence_number_of_last_sent_packet_ = sequence_number; 1332 sequence_number_of_last_sent_packet_ = sequence_number;
1335 1333
1336 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( 1334 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(
1337 packet.encryption_level, sequence_number, *packet.packet); 1335 packet.encryption_level, sequence_number, *packet.packet);
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 // If we changed the generator's batch state, restore original batch state. 1955 // If we changed the generator's batch state, restore original batch state.
1958 if (!already_in_batch_mode_) { 1956 if (!already_in_batch_mode_) {
1959 DVLOG(1) << "Leaving Batch Mode."; 1957 DVLOG(1) << "Leaving Batch Mode.";
1960 connection_->packet_generator_.FinishBatchOperations(); 1958 connection_->packet_generator_.FinishBatchOperations();
1961 } 1959 }
1962 DCHECK_EQ(already_in_batch_mode_, 1960 DCHECK_EQ(already_in_batch_mode_,
1963 connection_->packet_generator_.InBatchMode()); 1961 connection_->packet_generator_.InBatchMode());
1964 } 1962 }
1965 1963
1966 } // namespace net 1964 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_reliable_client_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698