| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef NET_SOCKET_TCP_SOCKET_POSIX_H_ | 5 #ifndef NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| 6 #define NET_SOCKET_TCP_SOCKET_POSIX_H_ | 6 #define NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/time/time.h" | |
| 16 #include "net/base/address_family.h" | 15 #include "net/base/address_family.h" |
| 17 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 18 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 19 #include "net/log/net_log_with_source.h" | 18 #include "net/log/net_log_with_source.h" |
| 20 #include "net/socket/socket_performance_watcher.h" | 19 #include "net/socket/socket_performance_watcher.h" |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class TickClock; | 22 class TimeDelta; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace net { | 25 namespace net { |
| 27 | 26 |
| 28 class AddressList; | 27 class AddressList; |
| 29 class IOBuffer; | 28 class IOBuffer; |
| 30 class IPEndPoint; | 29 class IPEndPoint; |
| 31 class SocketPosix; | 30 class SocketPosix; |
| 32 class NetLog; | 31 class NetLog; |
| 33 struct NetLogSource; | 32 struct NetLogSource; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // succeeds in establishing a connection. The corresponding log will have | 100 // succeeds in establishing a connection. The corresponding log will have |
| 102 // multiple NetLogEventType::TCP_CONNECT_ATTEMPT entries nested within a | 101 // multiple NetLogEventType::TCP_CONNECT_ATTEMPT entries nested within a |
| 103 // NetLogEventType::TCP_CONNECT. These methods set the start/end of | 102 // NetLogEventType::TCP_CONNECT. These methods set the start/end of |
| 104 // NetLogEventType::TCP_CONNECT. | 103 // NetLogEventType::TCP_CONNECT. |
| 105 // | 104 // |
| 106 // TODO(yzshen): Change logging format and let TCPClientSocket log the | 105 // TODO(yzshen): Change logging format and let TCPClientSocket log the |
| 107 // start/end of a series of connect attempts itself. | 106 // start/end of a series of connect attempts itself. |
| 108 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); | 107 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); |
| 109 void EndLoggingMultipleConnectAttempts(int net_error); | 108 void EndLoggingMultipleConnectAttempts(int net_error); |
| 110 | 109 |
| 111 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | |
| 112 | |
| 113 const NetLogWithSource& net_log() const { return net_log_; } | 110 const NetLogWithSource& net_log() const { return net_log_; } |
| 114 | 111 |
| 115 private: | 112 private: |
| 116 // States that using a socket with TCP FastOpen can lead to. | 113 // States that using a socket with TCP FastOpen can lead to. |
| 117 enum TCPFastOpenStatus { | 114 enum TCPFastOpenStatus { |
| 118 TCP_FASTOPEN_STATUS_UNKNOWN, | 115 TCP_FASTOPEN_STATUS_UNKNOWN, |
| 119 | 116 |
| 120 // The initial FastOpen connect attempted returned synchronously, | 117 // The initial FastOpen connect attempted returned synchronously, |
| 121 // indicating that we had and sent a cookie along with the initial data. | 118 // indicating that we had and sent a cookie along with the initial data. |
| 122 TCP_FASTOPEN_FAST_CONNECT_RETURN, | 119 TCP_FASTOPEN_FAST_CONNECT_RETURN, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Called after the first read completes on a TCP FastOpen socket. | 214 // Called after the first read completes on a TCP FastOpen socket. |
| 218 void UpdateTCPFastOpenStatusAfterRead(); | 215 void UpdateTCPFastOpenStatusAfterRead(); |
| 219 | 216 |
| 220 std::unique_ptr<SocketPosix> socket_; | 217 std::unique_ptr<SocketPosix> socket_; |
| 221 std::unique_ptr<SocketPosix> accept_socket_; | 218 std::unique_ptr<SocketPosix> accept_socket_; |
| 222 | 219 |
| 223 // Socket performance statistics (such as RTT) are reported to the | 220 // Socket performance statistics (such as RTT) are reported to the |
| 224 // |socket_performance_watcher_|. May be nullptr. | 221 // |socket_performance_watcher_|. May be nullptr. |
| 225 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher_; | 222 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher_; |
| 226 | 223 |
| 227 std::unique_ptr<base::TickClock> tick_clock_; | |
| 228 | |
| 229 // Minimum interval betweeen consecutive notifications to | |
| 230 // |socket_performance_watcher_|. | |
| 231 const base::TimeDelta rtt_notifications_minimum_interval_; | |
| 232 | |
| 233 // Time when the |socket_performance_watcher_| was last notified of updated | |
| 234 // RTT. | |
| 235 base::TimeTicks last_rtt_notification_; | |
| 236 | |
| 237 // Enables experimental TCP FastOpen option. | 224 // Enables experimental TCP FastOpen option. |
| 238 bool use_tcp_fastopen_; | 225 bool use_tcp_fastopen_; |
| 239 | 226 |
| 240 // True when TCP FastOpen is in use and we have attempted the | 227 // True when TCP FastOpen is in use and we have attempted the |
| 241 // connect with write. | 228 // connect with write. |
| 242 bool tcp_fastopen_write_attempted_; | 229 bool tcp_fastopen_write_attempted_; |
| 243 | 230 |
| 244 // True when TCP FastOpen is in use and we have done the connect. | 231 // True when TCP FastOpen is in use and we have done the connect. |
| 245 bool tcp_fastopen_connected_; | 232 bool tcp_fastopen_connected_; |
| 246 | 233 |
| 247 TCPFastOpenStatus tcp_fastopen_status_; | 234 TCPFastOpenStatus tcp_fastopen_status_; |
| 248 | 235 |
| 249 bool logging_multiple_connect_attempts_; | 236 bool logging_multiple_connect_attempts_; |
| 250 | 237 |
| 251 NetLogWithSource net_log_; | 238 NetLogWithSource net_log_; |
| 252 | 239 |
| 253 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); | 240 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); |
| 254 }; | 241 }; |
| 255 | 242 |
| 256 } // namespace net | 243 } // namespace net |
| 257 | 244 |
| 258 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ | 245 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| OLD | NEW |