| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 visitor_->PostProcessAfterData(); | 1380 visitor_->PostProcessAfterData(); |
| 1381 } | 1381 } |
| 1382 | 1382 |
| 1383 // After the visitor writes, it may have caused the socket to become write | 1383 // After the visitor writes, it may have caused the socket to become write |
| 1384 // blocked or the congestion manager to prohibit sending, so check again. | 1384 // blocked or the congestion manager to prohibit sending, so check again. |
| 1385 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && | 1385 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && |
| 1386 CanWrite(HAS_RETRANSMITTABLE_DATA)) { | 1386 CanWrite(HAS_RETRANSMITTABLE_DATA)) { |
| 1387 // We're not write blocked, but some stream didn't write out all of its | 1387 // We're not write blocked, but some stream didn't write out all of its |
| 1388 // bytes. Register for 'immediate' resumption so we'll keep writing after | 1388 // bytes. Register for 'immediate' resumption so we'll keep writing after |
| 1389 // other connections and events have had a chance to use the thread. | 1389 // other connections and events have had a chance to use the thread. |
| 1390 if (FLAGS_quic_only_one_sending_alarm) { | 1390 resume_writes_alarm_->Set(clock_->ApproximateNow()); |
| 1391 send_alarm_->Update(clock_->ApproximateNow(), QuicTime::Delta::Zero()); | |
| 1392 } else { | |
| 1393 resume_writes_alarm_->Set(clock_->ApproximateNow()); | |
| 1394 } | |
| 1395 } | 1391 } |
| 1396 } | 1392 } |
| 1397 | 1393 |
| 1398 void QuicConnection::WriteIfNotBlocked() { | 1394 void QuicConnection::WriteIfNotBlocked() { |
| 1399 if (!writer_->IsWriteBlocked()) { | 1395 if (!writer_->IsWriteBlocked()) { |
| 1400 OnCanWrite(); | 1396 OnCanWrite(); |
| 1401 } | 1397 } |
| 1402 } | 1398 } |
| 1403 | 1399 |
| 1404 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { | 1400 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 DCHECK(sent_packet_manager_->HasUnackedPackets()); | 1877 DCHECK(sent_packet_manager_->HasUnackedPackets()); |
| 1882 | 1878 |
| 1883 if (close_connection_after_five_rtos_ && | 1879 if (close_connection_after_five_rtos_ && |
| 1884 sent_packet_manager_->GetConsecutiveRtoCount() >= 4) { | 1880 sent_packet_manager_->GetConsecutiveRtoCount() >= 4) { |
| 1885 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. | 1881 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. |
| 1886 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", | 1882 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", |
| 1887 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 1883 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 1888 return; | 1884 return; |
| 1889 } | 1885 } |
| 1890 | 1886 |
| 1891 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated. | |
| 1892 if (FLAGS_quic_only_one_sending_alarm) { | |
| 1893 send_alarm_->Cancel(); | |
| 1894 } | |
| 1895 sent_packet_manager_->OnRetransmissionTimeout(); | 1887 sent_packet_manager_->OnRetransmissionTimeout(); |
| 1896 WriteIfNotBlocked(); | 1888 WriteIfNotBlocked(); |
| 1897 | 1889 |
| 1898 // A write failure can result in the connection being closed, don't attempt to | 1890 // A write failure can result in the connection being closed, don't attempt to |
| 1899 // write further packets, or to set alarms. | 1891 // write further packets, or to set alarms. |
| 1900 if (!connected_) { | 1892 if (!connected_) { |
| 1901 return; | 1893 return; |
| 1902 } | 1894 } |
| 1903 | 1895 |
| 1904 // In the TLP case, the SentPacketManager gives the connection the opportunity | 1896 // In the TLP case, the SentPacketManager gives the connection the opportunity |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2210 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); | 2202 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); |
| 2211 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), | 2203 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), |
| 2212 QuicTime::Delta::FromSeconds(1)); | 2204 QuicTime::Delta::FromSeconds(1)); |
| 2213 } | 2205 } |
| 2214 | 2206 |
| 2215 void QuicConnection::SetRetransmissionAlarm() { | 2207 void QuicConnection::SetRetransmissionAlarm() { |
| 2216 if (delay_setting_retransmission_alarm_) { | 2208 if (delay_setting_retransmission_alarm_) { |
| 2217 pending_retransmission_alarm_ = true; | 2209 pending_retransmission_alarm_ = true; |
| 2218 return; | 2210 return; |
| 2219 } | 2211 } |
| 2220 // Once the handshake has been confirmed, the retransmission alarm should | |
| 2221 // never fire before the send alarm. | |
| 2222 if (FLAGS_quic_only_one_sending_alarm && | |
| 2223 sent_packet_manager_->IsHandshakeConfirmed() && send_alarm_->IsSet()) { | |
| 2224 DCHECK(!sent_packet_manager_->GetRetransmissionTime().IsInitialized() || | |
| 2225 sent_packet_manager_->GetRetransmissionTime() >= | |
| 2226 send_alarm_->deadline()) | |
| 2227 << " retransmission_time:" | |
| 2228 << sent_packet_manager_->GetRetransmissionTime().ToDebuggingValue() | |
| 2229 << " send_alarm:" << send_alarm_->deadline().ToDebuggingValue(); | |
| 2230 retransmission_alarm_->Cancel(); | |
| 2231 return; | |
| 2232 } | |
| 2233 QuicTime retransmission_time = sent_packet_manager_->GetRetransmissionTime(); | 2212 QuicTime retransmission_time = sent_packet_manager_->GetRetransmissionTime(); |
| 2234 retransmission_alarm_->Update(retransmission_time, | 2213 retransmission_alarm_->Update(retransmission_time, |
| 2235 QuicTime::Delta::FromMilliseconds(1)); | 2214 QuicTime::Delta::FromMilliseconds(1)); |
| 2236 } | 2215 } |
| 2237 | 2216 |
| 2238 void QuicConnection::MaybeSetMtuAlarm() { | 2217 void QuicConnection::MaybeSetMtuAlarm() { |
| 2239 // Do not set the alarm if the target size is less than the current size. | 2218 // Do not set the alarm if the target size is less than the current size. |
| 2240 // This covers the case when |mtu_discovery_target_| is at its default value, | 2219 // This covers the case when |mtu_discovery_target_| is at its default value, |
| 2241 // zero. | 2220 // zero. |
| 2242 if (mtu_discovery_target_ <= max_packet_length()) { | 2221 if (mtu_discovery_target_ <= max_packet_length()) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2513 // the sender and a signaling mechanism -- if the sender uses a | 2492 // the sender and a signaling mechanism -- if the sender uses a |
| 2514 // different MinRTO, we may get spurious retransmissions. May not have | 2493 // different MinRTO, we may get spurious retransmissions. May not have |
| 2515 // any benefits, but if the delayed ack becomes a significant source | 2494 // any benefits, but if the delayed ack becomes a significant source |
| 2516 // of (likely, tail) latency, then consider such a mechanism. | 2495 // of (likely, tail) latency, then consider such a mechanism. |
| 2517 const QuicTime::Delta QuicConnection::DelayedAckTime() { | 2496 const QuicTime::Delta QuicConnection::DelayedAckTime() { |
| 2518 return QuicTime::Delta::FromMilliseconds( | 2497 return QuicTime::Delta::FromMilliseconds( |
| 2519 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2)); | 2498 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2)); |
| 2520 } | 2499 } |
| 2521 | 2500 |
| 2522 } // namespace net | 2501 } // namespace net |
| OLD | NEW |