| 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 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2049 // serialized packet. | 2049 // serialized packet. |
| 2050 SendConnectionClosePacket(error, details); | 2050 SendConnectionClosePacket(error, details); |
| 2051 CloseConnection(error, false); | 2051 CloseConnection(error, false); |
| 2052 } | 2052 } |
| 2053 | 2053 |
| 2054 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, | 2054 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, |
| 2055 const string& details) { | 2055 const string& details) { |
| 2056 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() << " with error " | 2056 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() << " with error " |
| 2057 << QuicUtils::ErrorToString(error) << " (" << error << ") " | 2057 << QuicUtils::ErrorToString(error) << " (" << error << ") " |
| 2058 << details; | 2058 << details; |
| 2059 // Don't send explicit connection close packets for timeouts. | |
| 2060 // This is particularly important on mobile, where connections are short. | |
| 2061 if (silent_close_enabled_ && | |
| 2062 error == QuicErrorCode::QUIC_NETWORK_IDLE_TIMEOUT) { | |
| 2063 return; | |
| 2064 } | |
| 2065 ClearQueuedPackets(); | 2059 ClearQueuedPackets(); |
| 2066 ScopedPacketBundler ack_bundler(this, SEND_ACK); | 2060 ScopedPacketBundler ack_bundler(this, SEND_ACK); |
| 2067 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 2061 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
| 2068 frame->error_code = error; | 2062 frame->error_code = error; |
| 2069 frame->error_details = details; | 2063 frame->error_details = details; |
| 2070 packet_generator_.AddControlFrame(QuicFrame(frame)); | 2064 packet_generator_.AddControlFrame(QuicFrame(frame)); |
| 2071 packet_generator_.FlushAllQueuedFrames(); | 2065 packet_generator_.FlushAllQueuedFrames(); |
| 2072 } | 2066 } |
| 2073 | 2067 |
| 2074 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { | 2068 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2206 // timeout handling. | 2200 // timeout handling. |
| 2207 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet); | 2201 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet); |
| 2208 DVLOG(1) << ENDPOINT << "last packet " | 2202 DVLOG(1) << ENDPOINT << "last packet " |
| 2209 << time_of_last_packet.ToDebuggingValue() | 2203 << time_of_last_packet.ToDebuggingValue() |
| 2210 << " now:" << now.ToDebuggingValue() | 2204 << " now:" << now.ToDebuggingValue() |
| 2211 << " idle_duration:" << idle_duration.ToMicroseconds() | 2205 << " idle_duration:" << idle_duration.ToMicroseconds() |
| 2212 << " idle_network_timeout: " | 2206 << " idle_network_timeout: " |
| 2213 << idle_network_timeout_.ToMicroseconds(); | 2207 << idle_network_timeout_.ToMicroseconds(); |
| 2214 if (idle_duration >= idle_network_timeout_) { | 2208 if (idle_duration >= idle_network_timeout_) { |
| 2215 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; | 2209 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; |
| 2216 SendConnectionCloseWithDetails(QUIC_NETWORK_IDLE_TIMEOUT, | 2210 if (silent_close_enabled_) { |
| 2217 "No recent network activity"); | 2211 // Just clean up local state, don't send a connection close packet. |
| 2212 CloseConnection(QUIC_NETWORK_IDLE_TIMEOUT, /*from_peer=*/false); |
| 2213 } else { |
| 2214 SendConnectionCloseWithDetails(QUIC_NETWORK_IDLE_TIMEOUT, |
| 2215 "No recent network activity"); |
| 2216 } |
| 2218 return; | 2217 return; |
| 2219 } | 2218 } |
| 2220 | 2219 |
| 2221 if (!handshake_timeout_.IsInfinite()) { | 2220 if (!handshake_timeout_.IsInfinite()) { |
| 2222 QuicTime::Delta connected_duration = | 2221 QuicTime::Delta connected_duration = |
| 2223 now.Subtract(stats_.connection_creation_time); | 2222 now.Subtract(stats_.connection_creation_time); |
| 2224 DVLOG(1) << ENDPOINT | 2223 DVLOG(1) << ENDPOINT |
| 2225 << "connection time: " << connected_duration.ToMicroseconds() | 2224 << "connection time: " << connected_duration.ToMicroseconds() |
| 2226 << " handshake timeout: " << handshake_timeout_.ToMicroseconds(); | 2225 << " handshake timeout: " << handshake_timeout_.ToMicroseconds(); |
| 2227 if (connected_duration >= handshake_timeout_) { | 2226 if (connected_duration >= handshake_timeout_) { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 void QuicConnection::OnPathClosed(QuicPathId path_id) { | 2533 void QuicConnection::OnPathClosed(QuicPathId path_id) { |
| 2535 // Stop receiving packets on this path. | 2534 // Stop receiving packets on this path. |
| 2536 framer_.OnPathClosed(path_id); | 2535 framer_.OnPathClosed(path_id); |
| 2537 } | 2536 } |
| 2538 | 2537 |
| 2539 bool QuicConnection::ack_frame_updated() const { | 2538 bool QuicConnection::ack_frame_updated() const { |
| 2540 return received_packet_manager_.ack_frame_updated(); | 2539 return received_packet_manager_.ack_frame_updated(); |
| 2541 } | 2540 } |
| 2542 | 2541 |
| 2543 } // namespace net | 2542 } // namespace net |
| OLD | NEW |