Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: net/quic/quic_connection.cc

Issue 593193005: Factor out the QUIC timeout alarm setting logic from the CheckForTimeout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Add_timestamp_field_75897792
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 if (FLAGS_quic_timeouts_require_activity && 1904 if (FLAGS_quic_timeouts_require_activity &&
1905 !time_of_last_packet.IsInitialized()) { 1905 !time_of_last_packet.IsInitialized()) {
1906 timeout_alarm_->Cancel(); 1906 timeout_alarm_->Cancel();
1907 timeout_alarm_->Set(now.Add(idle_network_timeout_)); 1907 timeout_alarm_->Set(now.Add(idle_network_timeout_));
1908 return; 1908 return;
1909 } 1909 }
1910 1910
1911 // |delta| can be < 0 as |now| is approximate time but |time_of_last_packet| 1911 // |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 1912 // is accurate time. However, this should not change the behavior of
1913 // timeout handling. 1913 // timeout handling.
1914 QuicTime::Delta delta = now.Subtract(time_of_last_packet); 1914 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet);
1915 DVLOG(1) << ENDPOINT << "last packet " 1915 DVLOG(1) << ENDPOINT << "last packet "
1916 << time_of_last_packet.ToDebuggingValue() 1916 << time_of_last_packet.ToDebuggingValue()
1917 << " now:" << now.ToDebuggingValue() 1917 << " now:" << now.ToDebuggingValue()
1918 << " delta:" << delta.ToMicroseconds() 1918 << " idle_duration:" << idle_duration.ToMicroseconds()
1919 << " network_timeout: " << idle_network_timeout_.ToMicroseconds(); 1919 << " idle_network_timeout: "
1920 if (delta >= idle_network_timeout_) { 1920 << idle_network_timeout_.ToMicroseconds();
1921 if (idle_duration >= idle_network_timeout_) {
1921 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; 1922 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity.";
1922 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT); 1923 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT);
1923 return; 1924 return;
1924 } 1925 }
1925 1926
1926 // Next timeout delta.
1927 QuicTime::Delta timeout = idle_network_timeout_.Subtract(delta);
1928
1929 if (!overall_connection_timeout_.IsInfinite()) { 1927 if (!overall_connection_timeout_.IsInfinite()) {
1930 QuicTime::Delta connected_time = 1928 QuicTime::Delta connected_duration =
1931 now.Subtract(stats_.connection_creation_time); 1929 now.Subtract(stats_.connection_creation_time);
1932 DVLOG(1) << ENDPOINT << "connection time: " 1930 DVLOG(1) << ENDPOINT << "connection time: "
1933 << connected_time.ToMilliseconds() << " overall timeout: " 1931 << connected_duration.ToMicroseconds() << " overall timeout: "
1934 << overall_connection_timeout_.ToMilliseconds(); 1932 << overall_connection_timeout_.ToMicroseconds();
1935 if (connected_time >= overall_connection_timeout_) { 1933 if (connected_duration >= overall_connection_timeout_) {
1936 DVLOG(1) << ENDPOINT << 1934 DVLOG(1) << ENDPOINT <<
1937 "Connection timedout due to overall connection timeout."; 1935 "Connection timedout due to overall connection timeout.";
1938 SendConnectionClose(QUIC_CONNECTION_OVERALL_TIMED_OUT); 1936 SendConnectionClose(QUIC_CONNECTION_OVERALL_TIMED_OUT);
1939 return; 1937 return;
1940 } 1938 }
1939 }
1941 1940
1942 // Take the min timeout. 1941 SetTimeoutAlarm();
1943 QuicTime::Delta connection_timeout = 1942 }
1944 overall_connection_timeout_.Subtract(connected_time); 1943
1945 if (connection_timeout < timeout) { 1944 void QuicConnection::SetTimeoutAlarm() {
1946 timeout = connection_timeout; 1945 QuicTime time_of_last_packet = max(time_of_last_received_packet_,
1947 } 1946 time_of_last_sent_new_packet_);
1947
1948 QuicTime deadline = time_of_last_packet.Add(idle_network_timeout_);
1949 if (!overall_connection_timeout_.IsInfinite()) {
1950 deadline = min(deadline,
1951 stats_.connection_creation_time.Add(
1952 overall_connection_timeout_));
1948 } 1953 }
1949 1954
1950 timeout_alarm_->Cancel(); 1955 timeout_alarm_->Cancel();
1951 timeout_alarm_->Set(now.Add(timeout)); 1956 timeout_alarm_->Set(deadline);
1952 } 1957 }
1953 1958
1954 void QuicConnection::SetPingAlarm() { 1959 void QuicConnection::SetPingAlarm() {
1955 if (is_server_) { 1960 if (is_server_) {
1956 // Only clients send pings. 1961 // Only clients send pings.
1957 return; 1962 return;
1958 } 1963 }
1959 if (!visitor_->HasOpenDataStreams()) { 1964 if (!visitor_->HasOpenDataStreams()) {
1960 ping_alarm_->Cancel(); 1965 ping_alarm_->Cancel();
1961 // Don't send a ping unless there are open streams. 1966 // Don't send a ping unless there are open streams.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 } 2030 }
2026 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2031 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2027 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2032 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2028 return true; 2033 return true;
2029 } 2034 }
2030 } 2035 }
2031 return false; 2036 return false;
2032 } 2037 }
2033 2038
2034 } // namespace net 2039 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698