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 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( | 952 if (CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)) { |
953 time_of_last_received_packet_, NOT_RETRANSMISSION, | 953 OnCanWrite(); |
954 HAS_RETRANSMITTABLE_DATA); | |
955 if (delay.IsZero()) { | |
956 send_alarm_->Cancel(); | |
957 WriteIfNotBlocked(); | |
958 } else if (!delay.IsInfinite()) { | |
959 send_alarm_->Cancel(); | |
960 send_alarm_->Set(time_of_last_received_packet_.Add(delay)); | |
961 } | 954 } |
962 } | 955 } |
963 | 956 |
964 void QuicConnection::SendVersionNegotiationPacket() { | 957 void QuicConnection::SendVersionNegotiationPacket() { |
965 // TODO(alyssar): implement zero server state negotiation. | 958 // TODO(alyssar): implement zero server state negotiation. |
966 pending_version_negotiation_packet_ = true; | 959 pending_version_negotiation_packet_ = true; |
967 if (writer_->IsWriteBlocked()) { | 960 if (writer_->IsWriteBlocked()) { |
968 visitor_->OnWriteBlocked(); | 961 visitor_->OnWriteBlocked(); |
969 return; | 962 return; |
970 } | 963 } |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 return CanWrite(transmission_type, retransmittable); | 1284 return CanWrite(transmission_type, retransmittable); |
1292 } | 1285 } |
1293 | 1286 |
1294 bool QuicConnection::CanWrite(TransmissionType transmission_type, | 1287 bool QuicConnection::CanWrite(TransmissionType transmission_type, |
1295 HasRetransmittableData retransmittable) { | 1288 HasRetransmittableData retransmittable) { |
1296 if (writer_->IsWriteBlocked()) { | 1289 if (writer_->IsWriteBlocked()) { |
1297 visitor_->OnWriteBlocked(); | 1290 visitor_->OnWriteBlocked(); |
1298 return false; | 1291 return false; |
1299 } | 1292 } |
1300 | 1293 |
1301 // TODO(rch): consider removing this check so that if an ACK comes in | 1294 send_alarm_->Cancel(); |
1302 // before the alarm goes it, we might be able send out a packet. | |
1303 // This check assumes that if the send alarm is set, it applies equally to all | |
1304 // types of transmissions. | |
1305 if (send_alarm_->IsSet()) { | |
1306 DVLOG(1) << "Send alarm set. Not sending."; | |
1307 return false; | |
1308 } | |
1309 | |
1310 QuicTime now = clock_->Now(); | 1295 QuicTime now = clock_->Now(); |
1311 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( | 1296 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( |
1312 now, transmission_type, retransmittable); | 1297 now, transmission_type, retransmittable); |
1313 if (delay.IsInfinite()) { | 1298 if (delay.IsInfinite()) { |
1314 return false; | 1299 return false; |
1315 } | 1300 } |
1316 | 1301 |
1317 // If the scheduler requires a delay, then we can not send this packet now. | 1302 // If the scheduler requires a delay, then we can not send this packet now. |
1318 if (!delay.IsZero()) { | 1303 if (!delay.IsZero()) { |
1319 send_alarm_->Cancel(); | |
1320 send_alarm_->Set(now.Add(delay)); | 1304 send_alarm_->Set(now.Add(delay)); |
1321 DVLOG(1) << "Delaying sending."; | 1305 DVLOG(1) << "Delaying sending."; |
1322 return false; | 1306 return false; |
1323 } | 1307 } |
1324 return true; | 1308 return true; |
1325 } | 1309 } |
1326 | 1310 |
1327 bool QuicConnection::WritePacket(QueuedPacket packet) { | 1311 bool QuicConnection::WritePacket(QueuedPacket packet) { |
1328 QuicPacketSequenceNumber sequence_number = packet.sequence_number; | 1312 QuicPacketSequenceNumber sequence_number = packet.sequence_number; |
1329 if (ShouldDiscardPacket(packet.encryption_level, | 1313 if (ShouldDiscardPacket(packet.encryption_level, |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1973 // If we changed the generator's batch state, restore original batch state. | 1957 // If we changed the generator's batch state, restore original batch state. |
1974 if (!already_in_batch_mode_) { | 1958 if (!already_in_batch_mode_) { |
1975 DVLOG(1) << "Leaving Batch Mode."; | 1959 DVLOG(1) << "Leaving Batch Mode."; |
1976 connection_->packet_generator_.FinishBatchOperations(); | 1960 connection_->packet_generator_.FinishBatchOperations(); |
1977 } | 1961 } |
1978 DCHECK_EQ(already_in_batch_mode_, | 1962 DCHECK_EQ(already_in_batch_mode_, |
1979 connection_->packet_generator_.InBatchMode()); | 1963 connection_->packet_generator_.InBatchMode()); |
1980 } | 1964 } |
1981 | 1965 |
1982 } // namespace net | 1966 } // namespace net |
OLD | NEW |