| 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 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 visitor_->PostProcessAfterData(); | 1357 visitor_->PostProcessAfterData(); |
| 1358 } | 1358 } |
| 1359 | 1359 |
| 1360 // After the visitor writes, it may have caused the socket to become write | 1360 // After the visitor writes, it may have caused the socket to become write |
| 1361 // blocked or the congestion manager to prohibit sending, so check again. | 1361 // blocked or the congestion manager to prohibit sending, so check again. |
| 1362 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && | 1362 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && |
| 1363 CanWrite(HAS_RETRANSMITTABLE_DATA)) { | 1363 CanWrite(HAS_RETRANSMITTABLE_DATA)) { |
| 1364 // We're not write blocked, but some stream didn't write out all of its | 1364 // We're not write blocked, but some stream didn't write out all of its |
| 1365 // bytes. Register for 'immediate' resumption so we'll keep writing after | 1365 // bytes. Register for 'immediate' resumption so we'll keep writing after |
| 1366 // other connections and events have had a chance to use the thread. | 1366 // other connections and events have had a chance to use the thread. |
| 1367 resume_writes_alarm_->Set(clock_->ApproximateNow()); | 1367 if (FLAGS_quic_only_one_sending_alarm) { |
| 1368 send_alarm_->Update(clock_->ApproximateNow(), QuicTime::Delta::Zero()); |
| 1369 } else { |
| 1370 resume_writes_alarm_->Set(clock_->ApproximateNow()); |
| 1371 } |
| 1368 } | 1372 } |
| 1369 } | 1373 } |
| 1370 | 1374 |
| 1371 void QuicConnection::WriteIfNotBlocked() { | 1375 void QuicConnection::WriteIfNotBlocked() { |
| 1372 if (!writer_->IsWriteBlocked()) { | 1376 if (!writer_->IsWriteBlocked()) { |
| 1373 OnCanWrite(); | 1377 OnCanWrite(); |
| 1374 } | 1378 } |
| 1375 } | 1379 } |
| 1376 | 1380 |
| 1377 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { | 1381 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1848 } | 1852 } |
| 1849 | 1853 |
| 1850 if (close_connection_after_five_rtos_ && | 1854 if (close_connection_after_five_rtos_ && |
| 1851 sent_packet_manager_.consecutive_rto_count() >= 4) { | 1855 sent_packet_manager_.consecutive_rto_count() >= 4) { |
| 1852 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. | 1856 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. |
| 1853 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", | 1857 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", |
| 1854 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 1858 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 1855 return; | 1859 return; |
| 1856 } | 1860 } |
| 1857 | 1861 |
| 1862 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated. |
| 1863 if (FLAGS_quic_only_one_sending_alarm) { |
| 1864 send_alarm_->Cancel(); |
| 1865 } |
| 1858 sent_packet_manager_.OnRetransmissionTimeout(); | 1866 sent_packet_manager_.OnRetransmissionTimeout(); |
| 1859 WriteIfNotBlocked(); | 1867 WriteIfNotBlocked(); |
| 1860 | 1868 |
| 1861 // A write failure can result in the connection being closed, don't attempt to | 1869 // A write failure can result in the connection being closed, don't attempt to |
| 1862 // write further packets, or to set alarms. | 1870 // write further packets, or to set alarms. |
| 1863 if (!connected_) { | 1871 if (!connected_) { |
| 1864 return; | 1872 return; |
| 1865 } | 1873 } |
| 1866 | 1874 |
| 1867 // In the TLP case, the SentPacketManager gives the connection the opportunity | 1875 // In the TLP case, the SentPacketManager gives the connection the opportunity |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2169 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); | 2177 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); |
| 2170 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), | 2178 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), |
| 2171 QuicTime::Delta::FromSeconds(1)); | 2179 QuicTime::Delta::FromSeconds(1)); |
| 2172 } | 2180 } |
| 2173 | 2181 |
| 2174 void QuicConnection::SetRetransmissionAlarm() { | 2182 void QuicConnection::SetRetransmissionAlarm() { |
| 2175 if (delay_setting_retransmission_alarm_) { | 2183 if (delay_setting_retransmission_alarm_) { |
| 2176 pending_retransmission_alarm_ = true; | 2184 pending_retransmission_alarm_ = true; |
| 2177 return; | 2185 return; |
| 2178 } | 2186 } |
| 2187 // Once the handshake has been confirmed, the retransmission alarm should |
| 2188 // never fire before the send alarm. |
| 2189 if (FLAGS_quic_only_one_sending_alarm && |
| 2190 sent_packet_manager_.handshake_confirmed() && send_alarm_->IsSet()) { |
| 2191 DCHECK(!sent_packet_manager_.GetRetransmissionTime().IsInitialized() || |
| 2192 sent_packet_manager_.GetRetransmissionTime() >= |
| 2193 send_alarm_->deadline()) |
| 2194 << " retransmission_time:" |
| 2195 << sent_packet_manager_.GetRetransmissionTime().ToDebuggingValue() |
| 2196 << " send_alarm:" << send_alarm_->deadline().ToDebuggingValue(); |
| 2197 retransmission_alarm_->Cancel(); |
| 2198 return; |
| 2199 } |
| 2179 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); | 2200 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); |
| 2180 retransmission_alarm_->Update(retransmission_time, | 2201 retransmission_alarm_->Update(retransmission_time, |
| 2181 QuicTime::Delta::FromMilliseconds(1)); | 2202 QuicTime::Delta::FromMilliseconds(1)); |
| 2182 } | 2203 } |
| 2183 | 2204 |
| 2184 void QuicConnection::MaybeSetMtuAlarm() { | 2205 void QuicConnection::MaybeSetMtuAlarm() { |
| 2185 // Do not set the alarm if the target size is less than the current size. | 2206 // Do not set the alarm if the target size is less than the current size. |
| 2186 // This covers the case when |mtu_discovery_target_| is at its default value, | 2207 // This covers the case when |mtu_discovery_target_| is at its default value, |
| 2187 // zero. | 2208 // zero. |
| 2188 if (mtu_discovery_target_ <= max_packet_length()) { | 2209 if (mtu_discovery_target_ <= max_packet_length()) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 } | 2436 } |
| 2416 | 2437 |
| 2417 StringPiece QuicConnection::GetCurrentPacket() { | 2438 StringPiece QuicConnection::GetCurrentPacket() { |
| 2418 if (current_packet_data_ == nullptr) { | 2439 if (current_packet_data_ == nullptr) { |
| 2419 return StringPiece(); | 2440 return StringPiece(); |
| 2420 } | 2441 } |
| 2421 return StringPiece(current_packet_data_, last_size_); | 2442 return StringPiece(current_packet_data_, last_size_); |
| 2422 } | 2443 } |
| 2423 | 2444 |
| 2424 } // namespace net | 2445 } // namespace net |
| OLD | NEW |