Chromium Code Reviews| 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 #include "net/socket/tcp_socket.h" | 5 #include "net/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <netinet/tcp.h> | 8 #include <netinet/tcp.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
| 17 #include "base/strings/string_number_conversions.h" | |
| 18 #include "base/strings/string_piece.h" | |
| 17 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
| 18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 19 #include "net/base/address_list.h" | 21 #include "net/base/address_list.h" |
| 20 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 21 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
| 22 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 23 #include "net/base/network_activity_monitor.h" | 25 #include "net/base/network_activity_monitor.h" |
| 24 #include "net/base/network_change_notifier.h" | 26 #include "net/base/network_change_notifier.h" |
| 25 #include "net/base/sockaddr_storage.h" | 27 #include "net/base/sockaddr_storage.h" |
| 26 #include "net/log/net_log.h" | 28 #include "net/log/net_log.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 #if defined(OS_LINUX) || defined(OS_ANDROID) | 87 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 86 // Checks if the kernel supports TCP FastOpen. | 88 // Checks if the kernel supports TCP FastOpen. |
| 87 bool SystemSupportsTCPFastOpen() { | 89 bool SystemSupportsTCPFastOpen() { |
| 88 const base::FilePath::CharType kTCPFastOpenProcFilePath[] = | 90 const base::FilePath::CharType kTCPFastOpenProcFilePath[] = |
| 89 "/proc/sys/net/ipv4/tcp_fastopen"; | 91 "/proc/sys/net/ipv4/tcp_fastopen"; |
| 90 std::string system_supports_tcp_fastopen; | 92 std::string system_supports_tcp_fastopen; |
| 91 if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath), | 93 if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath), |
| 92 &system_supports_tcp_fastopen)) { | 94 &system_supports_tcp_fastopen)) { |
| 93 return false; | 95 return false; |
| 94 } | 96 } |
| 95 // The read from /proc should return '1' if TCP FastOpen is enabled in the OS. | 97 // The read value from /proc will be set in its least significant bit if |
| 98 // TCP FastOpen is enabled. | |
| 99 int read_int = 0; | |
| 96 if (system_supports_tcp_fastopen.empty() || | 100 if (system_supports_tcp_fastopen.empty() || |
| 97 (system_supports_tcp_fastopen[0] != '1')) { | 101 !StringToInt(StringPiece(system_supports_tcp_fastopen), &read_int) || |
|
Randy Smith (Not in Mondays)
2017/02/23 15:15:32
Are you comfortable with this failing if there's l
Jana
2017/02/24 19:24:44
I've added whitespace trimming, PTAL.
| |
| 102 (read_int & 0x1) != 1) { | |
| 98 return false; | 103 return false; |
| 99 } | 104 } |
| 100 return true; | 105 return true; |
| 101 } | 106 } |
| 102 | 107 |
| 103 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled, | 108 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled, |
| 104 bool system_supported) { | 109 bool system_supported) { |
| 105 g_tcp_fastopen_supported = system_supported; | 110 g_tcp_fastopen_supported = system_supported; |
| 106 g_tcp_fastopen_user_enabled = user_enabled; | 111 g_tcp_fastopen_user_enabled = user_enabled; |
| 107 } | 112 } |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 if (info.tcpi_rtt > 0) { | 799 if (info.tcpi_rtt > 0) { |
| 795 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); | 800 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); |
| 796 return true; | 801 return true; |
| 797 } | 802 } |
| 798 } | 803 } |
| 799 #endif // defined(TCP_INFO) | 804 #endif // defined(TCP_INFO) |
| 800 return false; | 805 return false; |
| 801 } | 806 } |
| 802 | 807 |
| 803 } // namespace net | 808 } // namespace net |
| OLD | NEW |