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_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 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 self_port_changed_ = (self_address.port() != self_address_.port()); | 1161 self_port_changed_ = (self_address.port() != self_address_.port()); |
1162 } | 1162 } |
1163 } | 1163 } |
1164 | 1164 |
1165 void QuicConnection::OnCanWrite() { | 1165 void QuicConnection::OnCanWrite() { |
1166 DCHECK(!writer_->IsWriteBlocked()); | 1166 DCHECK(!writer_->IsWriteBlocked()); |
1167 | 1167 |
1168 WriteQueuedPackets(); | 1168 WriteQueuedPackets(); |
1169 WritePendingRetransmissions(); | 1169 WritePendingRetransmissions(); |
1170 | 1170 |
1171 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ? | |
1172 IS_HANDSHAKE : NOT_HANDSHAKE; | |
1173 // Sending queued packets may have caused the socket to become write blocked, | 1171 // Sending queued packets may have caused the socket to become write blocked, |
1174 // or the congestion manager to prohibit sending. If we've sent everything | 1172 // or the congestion manager to prohibit sending. If we've sent everything |
1175 // we had queued and we're still not blocked, let the visitor know it can | 1173 // we had queued and we're still not blocked, let the visitor know it can |
1176 // write more. | 1174 // write more. |
1177 if (!CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, | 1175 if (!CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)) { |
1178 pending_handshake)) { | |
1179 return; | 1176 return; |
1180 } | 1177 } |
1181 | 1178 |
1182 { // Limit the scope of the bundler. | 1179 { // Limit the scope of the bundler. |
1183 // Set |include_ack| to false in bundler; ack inclusion happens elsewhere. | 1180 // Set |include_ack| to false in bundler; ack inclusion happens elsewhere. |
1184 ScopedPacketBundler bundler(this, NO_ACK); | 1181 ScopedPacketBundler bundler(this, NO_ACK); |
1185 visitor_->OnCanWrite(); | 1182 visitor_->OnCanWrite(); |
1186 } | 1183 } |
1187 | 1184 |
1188 // After the visitor writes, it may have caused the socket to become write | 1185 // After the visitor writes, it may have caused the socket to become write |
1189 // blocked or the congestion manager to prohibit sending, so check again. | 1186 // blocked or the congestion manager to prohibit sending, so check again. |
1190 pending_handshake = visitor_->HasPendingHandshake() ? | |
1191 IS_HANDSHAKE : NOT_HANDSHAKE; | |
1192 if (visitor_->HasPendingWrites() && !resume_writes_alarm_->IsSet() && | 1187 if (visitor_->HasPendingWrites() && !resume_writes_alarm_->IsSet() && |
1193 CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, | 1188 CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)) { |
1194 pending_handshake)) { | |
1195 // We're not write blocked, but some stream didn't write out all of its | 1189 // We're not write blocked, but some stream didn't write out all of its |
1196 // bytes. Register for 'immediate' resumption so we'll keep writing after | 1190 // bytes. Register for 'immediate' resumption so we'll keep writing after |
1197 // other connections and events have had a chance to use the thread. | 1191 // other connections and events have had a chance to use the thread. |
1198 resume_writes_alarm_->Set(clock_->ApproximateNow()); | 1192 resume_writes_alarm_->Set(clock_->ApproximateNow()); |
1199 } | 1193 } |
1200 } | 1194 } |
1201 | 1195 |
1202 void QuicConnection::WriteIfNotBlocked() { | 1196 void QuicConnection::WriteIfNotBlocked() { |
1203 if (!writer_->IsWriteBlocked()) { | 1197 if (!writer_->IsWriteBlocked()) { |
1204 OnCanWrite(); | 1198 OnCanWrite(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 } | 1249 } |
1256 } | 1250 } |
1257 | 1251 |
1258 void QuicConnection::WritePendingRetransmissions() { | 1252 void QuicConnection::WritePendingRetransmissions() { |
1259 // Keep writing as long as there's a pending retransmission which can be | 1253 // Keep writing as long as there's a pending retransmission which can be |
1260 // written. | 1254 // written. |
1261 while (sent_packet_manager_.HasPendingRetransmissions()) { | 1255 while (sent_packet_manager_.HasPendingRetransmissions()) { |
1262 const QuicSentPacketManager::PendingRetransmission pending = | 1256 const QuicSentPacketManager::PendingRetransmission pending = |
1263 sent_packet_manager_.NextPendingRetransmission(); | 1257 sent_packet_manager_.NextPendingRetransmission(); |
1264 if (GetPacketType(&pending.retransmittable_frames) == NORMAL && | 1258 if (GetPacketType(&pending.retransmittable_frames) == NORMAL && |
1265 !CanWrite(pending.transmission_type, HAS_RETRANSMITTABLE_DATA, | 1259 !CanWrite(pending.transmission_type, HAS_RETRANSMITTABLE_DATA)) { |
1266 pending.retransmittable_frames.HasCryptoHandshake())) { | |
1267 break; | 1260 break; |
1268 } | 1261 } |
1269 | 1262 |
1270 // Re-packetize the frames with a new sequence number for retransmission. | 1263 // Re-packetize the frames with a new sequence number for retransmission. |
1271 // Retransmitted data packets do not use FEC, even when it's enabled. | 1264 // Retransmitted data packets do not use FEC, even when it's enabled. |
1272 // Retransmitted packets use the same sequence number length as the | 1265 // Retransmitted packets use the same sequence number length as the |
1273 // original. | 1266 // original. |
1274 // Flush the packet creator before making a new packet. | 1267 // Flush the packet creator before making a new packet. |
1275 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that | 1268 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that |
1276 // does not require the creator to be flushed. | 1269 // does not require the creator to be flushed. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 bool QuicConnection::ShouldGeneratePacket( | 1307 bool QuicConnection::ShouldGeneratePacket( |
1315 TransmissionType transmission_type, | 1308 TransmissionType transmission_type, |
1316 HasRetransmittableData retransmittable, | 1309 HasRetransmittableData retransmittable, |
1317 IsHandshake handshake) { | 1310 IsHandshake handshake) { |
1318 // We should serialize handshake packets immediately to ensure that they | 1311 // We should serialize handshake packets immediately to ensure that they |
1319 // end up sent at the right encryption level. | 1312 // end up sent at the right encryption level. |
1320 if (handshake == IS_HANDSHAKE) { | 1313 if (handshake == IS_HANDSHAKE) { |
1321 return true; | 1314 return true; |
1322 } | 1315 } |
1323 | 1316 |
1324 return CanWrite(transmission_type, retransmittable, handshake); | 1317 return CanWrite(transmission_type, retransmittable); |
1325 } | 1318 } |
1326 | 1319 |
1327 bool QuicConnection::CanWrite(TransmissionType transmission_type, | 1320 bool QuicConnection::CanWrite(TransmissionType transmission_type, |
1328 HasRetransmittableData retransmittable, | 1321 HasRetransmittableData retransmittable) { |
1329 IsHandshake handshake) { | |
1330 if (writer_->IsWriteBlocked()) { | 1322 if (writer_->IsWriteBlocked()) { |
1331 visitor_->OnWriteBlocked(); | 1323 visitor_->OnWriteBlocked(); |
1332 return false; | 1324 return false; |
1333 } | 1325 } |
1334 | 1326 |
1335 // TODO(rch): consider removing this check so that if an ACK comes in | 1327 // TODO(rch): consider removing this check so that if an ACK comes in |
1336 // before the alarm goes it, we might be able send out a packet. | 1328 // before the alarm goes it, we might be able send out a packet. |
1337 // This check assumes that if the send alarm is set, it applies equally to all | 1329 // This check assumes that if the send alarm is set, it applies equally to all |
1338 // types of transmissions. | 1330 // types of transmissions. |
1339 if (send_alarm_->IsSet()) { | 1331 if (send_alarm_->IsSet()) { |
(...skipping 27 matching lines...) Expand all Loading... |
1367 return true; | 1359 return true; |
1368 } | 1360 } |
1369 | 1361 |
1370 // If the packet is CONNECTION_CLOSE, we need to try to send it immediately | 1362 // If the packet is CONNECTION_CLOSE, we need to try to send it immediately |
1371 // and encrypt it to hand it off to TimeWaitListManager. | 1363 // and encrypt it to hand it off to TimeWaitListManager. |
1372 // If the packet is QUEUED, we don't re-consult the congestion control. | 1364 // If the packet is QUEUED, we don't re-consult the congestion control. |
1373 // This ensures packets are sent in sequence number order. | 1365 // This ensures packets are sent in sequence number order. |
1374 // TODO(ianswett): The congestion control should have been consulted before | 1366 // TODO(ianswett): The congestion control should have been consulted before |
1375 // serializing the packet, so this could be turned into a LOG_IF(DFATAL). | 1367 // serializing the packet, so this could be turned into a LOG_IF(DFATAL). |
1376 if (packet.type == NORMAL && !CanWrite(packet.transmission_type, | 1368 if (packet.type == NORMAL && !CanWrite(packet.transmission_type, |
1377 packet.retransmittable, | 1369 packet.retransmittable)) { |
1378 packet.handshake)) { | |
1379 return false; | 1370 return false; |
1380 } | 1371 } |
1381 | 1372 |
1382 // Some encryption algorithms require the packet sequence numbers not be | 1373 // Some encryption algorithms require the packet sequence numbers not be |
1383 // repeated. | 1374 // repeated. |
1384 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); | 1375 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); |
1385 sequence_number_of_last_sent_packet_ = sequence_number; | 1376 sequence_number_of_last_sent_packet_ = sequence_number; |
1386 | 1377 |
1387 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( | 1378 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( |
1388 packet.encryption_level, sequence_number, *packet.packet); | 1379 packet.encryption_level, sequence_number, *packet.packet); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1998 // If we changed the generator's batch state, restore original batch state. | 1989 // If we changed the generator's batch state, restore original batch state. |
1999 if (!already_in_batch_mode_) { | 1990 if (!already_in_batch_mode_) { |
2000 DVLOG(1) << "Leaving Batch Mode."; | 1991 DVLOG(1) << "Leaving Batch Mode."; |
2001 connection_->packet_generator_.FinishBatchOperations(); | 1992 connection_->packet_generator_.FinishBatchOperations(); |
2002 } | 1993 } |
2003 DCHECK_EQ(already_in_batch_mode_, | 1994 DCHECK_EQ(already_in_batch_mode_, |
2004 connection_->packet_generator_.InBatchMode()); | 1995 connection_->packet_generator_.InBatchMode()); |
2005 } | 1996 } |
2006 | 1997 |
2007 } // namespace net | 1998 } // namespace net |
OLD | NEW |