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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 212 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
213 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 213 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
214 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 214 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
215 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 215 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
216 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 216 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
217 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), | 217 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), |
218 packet_generator_(connection_id_, &framer_, random_generator_, this), | 218 packet_generator_(connection_id_, &framer_, random_generator_, this), |
219 idle_network_timeout_( | 219 idle_network_timeout_( |
220 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), | 220 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), |
221 overall_connection_timeout_(QuicTime::Delta::Infinite()), | 221 overall_connection_timeout_(QuicTime::Delta::Infinite()), |
222 time_of_last_received_packet_( | 222 time_of_last_received_packet_(clock_->ApproximateNow()), |
223 FLAGS_quic_timeouts_require_activity | 223 time_of_last_sent_new_packet_(clock_->ApproximateNow()), |
224 ? QuicTime::Zero() : clock_->ApproximateNow()), | |
225 time_of_last_sent_new_packet_( | |
226 FLAGS_quic_timeouts_require_activity | |
227 ? QuicTime::Zero() : clock_->ApproximateNow()), | |
228 sequence_number_of_last_sent_packet_(0), | 224 sequence_number_of_last_sent_packet_(0), |
229 sent_packet_manager_( | 225 sent_packet_manager_( |
230 is_server, clock_, &stats_, | 226 is_server, clock_, &stats_, |
231 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, | 227 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, |
232 FLAGS_quic_use_time_loss_detection ? kTime : kNack), | 228 FLAGS_quic_use_time_loss_detection ? kTime : kNack), |
233 version_negotiation_state_(START_NEGOTIATION), | 229 version_negotiation_state_(START_NEGOTIATION), |
234 is_server_(is_server), | 230 is_server_(is_server), |
235 connected_(true), | 231 connected_(true), |
236 peer_ip_changed_(false), | 232 peer_ip_changed_(false), |
237 peer_port_changed_(false), | 233 peer_port_changed_(false), |
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 // Adjust the idle timeout on client and server to prevent clients from | 1869 // Adjust the idle timeout on client and server to prevent clients from |
1874 // sending requests to servers which have already closed the connection. | 1870 // sending requests to servers which have already closed the connection. |
1875 if (is_server_) { | 1871 if (is_server_) { |
1876 timeout = timeout.Add(QuicTime::Delta::FromSeconds(1)); | 1872 timeout = timeout.Add(QuicTime::Delta::FromSeconds(1)); |
1877 } else if (timeout > QuicTime::Delta::FromSeconds(1)) { | 1873 } else if (timeout > QuicTime::Delta::FromSeconds(1)) { |
1878 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1)); | 1874 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1)); |
1879 } | 1875 } |
1880 | 1876 |
1881 if (timeout < idle_network_timeout_) { | 1877 if (timeout < idle_network_timeout_) { |
1882 idle_network_timeout_ = timeout; | 1878 idle_network_timeout_ = timeout; |
1883 CheckForTimeout(); | 1879 if (FLAGS_quic_timeouts_only_from_alarms) { |
| 1880 SetTimeoutAlarm(); |
| 1881 } else { |
| 1882 CheckForTimeout(); |
| 1883 } |
1884 } else { | 1884 } else { |
1885 idle_network_timeout_ = timeout; | 1885 idle_network_timeout_ = timeout; |
1886 } | 1886 } |
1887 } | 1887 } |
1888 | 1888 |
1889 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { | 1889 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { |
1890 if (timeout < overall_connection_timeout_) { | 1890 if (timeout < overall_connection_timeout_) { |
1891 overall_connection_timeout_ = timeout; | 1891 overall_connection_timeout_ = timeout; |
1892 CheckForTimeout(); | 1892 if (FLAGS_quic_timeouts_only_from_alarms) { |
| 1893 SetTimeoutAlarm(); |
| 1894 } else { |
| 1895 CheckForTimeout(); |
| 1896 } |
1893 } else { | 1897 } else { |
1894 overall_connection_timeout_ = timeout; | 1898 overall_connection_timeout_ = timeout; |
1895 } | 1899 } |
1896 } | 1900 } |
1897 | 1901 |
1898 void QuicConnection::CheckForTimeout() { | 1902 void QuicConnection::CheckForTimeout() { |
1899 QuicTime now = clock_->ApproximateNow(); | 1903 QuicTime now = clock_->ApproximateNow(); |
1900 QuicTime time_of_last_packet = max(time_of_last_received_packet_, | 1904 QuicTime time_of_last_packet = max(time_of_last_received_packet_, |
1901 time_of_last_sent_new_packet_); | 1905 time_of_last_sent_new_packet_); |
1902 | 1906 |
1903 // If no packets have been sent or received, then don't timeout. | |
1904 if (FLAGS_quic_timeouts_require_activity && | |
1905 !time_of_last_packet.IsInitialized()) { | |
1906 timeout_alarm_->Cancel(); | |
1907 timeout_alarm_->Set(now.Add(idle_network_timeout_)); | |
1908 return; | |
1909 } | |
1910 | |
1911 // |delta| can be < 0 as |now| is approximate time but |time_of_last_packet| | 1907 // |delta| can be < 0 as |now| is approximate time but |time_of_last_packet| |
1912 // is accurate time. However, this should not change the behavior of | 1908 // is accurate time. However, this should not change the behavior of |
1913 // timeout handling. | 1909 // timeout handling. |
1914 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet); | 1910 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet); |
1915 DVLOG(1) << ENDPOINT << "last packet " | 1911 DVLOG(1) << ENDPOINT << "last packet " |
1916 << time_of_last_packet.ToDebuggingValue() | 1912 << time_of_last_packet.ToDebuggingValue() |
1917 << " now:" << now.ToDebuggingValue() | 1913 << " now:" << now.ToDebuggingValue() |
1918 << " idle_duration:" << idle_duration.ToMicroseconds() | 1914 << " idle_duration:" << idle_duration.ToMicroseconds() |
1919 << " idle_network_timeout: " | 1915 << " idle_network_timeout: " |
1920 << idle_network_timeout_.ToMicroseconds(); | 1916 << idle_network_timeout_.ToMicroseconds(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2030 } | 2026 } |
2031 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2027 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
2032 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2028 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
2033 return true; | 2029 return true; |
2034 } | 2030 } |
2035 } | 2031 } |
2036 return false; | 2032 return false; |
2037 } | 2033 } |
2038 | 2034 |
2039 } // namespace net | 2035 } // namespace net |
OLD | NEW |