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

Side by Side Diff: net/socket/tcp_socket_posix.cc

Issue 2705323002: Fix incorrect behavior in checking for TCP FastOpen platform support. (Closed)
Patch Set: Trim leading whitespace. Created 3 years, 10 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 | « no previous file | 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 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"
28 #include "net/http/http_util.h"
26 #include "net/log/net_log.h" 29 #include "net/log/net_log.h"
27 #include "net/log/net_log_event_type.h" 30 #include "net/log/net_log_event_type.h"
28 #include "net/log/net_log_source.h" 31 #include "net/log/net_log_source.h"
29 #include "net/log/net_log_source_type.h" 32 #include "net/log/net_log_source_type.h"
30 #include "net/socket/socket_net_log_params.h" 33 #include "net/socket/socket_net_log_params.h"
31 #include "net/socket/socket_posix.h" 34 #include "net/socket/socket_posix.h"
32 35
33 // If we don't have a definition for TCPI_OPT_SYN_DATA, create one. 36 // If we don't have a definition for TCPI_OPT_SYN_DATA, create one.
34 #ifndef TCPI_OPT_SYN_DATA 37 #ifndef TCPI_OPT_SYN_DATA
35 #define TCPI_OPT_SYN_DATA 32 38 #define TCPI_OPT_SYN_DATA 32
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #if defined(OS_LINUX) || defined(OS_ANDROID) 88 #if defined(OS_LINUX) || defined(OS_ANDROID)
86 // Checks if the kernel supports TCP FastOpen. 89 // Checks if the kernel supports TCP FastOpen.
87 bool SystemSupportsTCPFastOpen() { 90 bool SystemSupportsTCPFastOpen() {
88 const base::FilePath::CharType kTCPFastOpenProcFilePath[] = 91 const base::FilePath::CharType kTCPFastOpenProcFilePath[] =
89 "/proc/sys/net/ipv4/tcp_fastopen"; 92 "/proc/sys/net/ipv4/tcp_fastopen";
90 std::string system_supports_tcp_fastopen; 93 std::string system_supports_tcp_fastopen;
91 if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath), 94 if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath),
92 &system_supports_tcp_fastopen)) { 95 &system_supports_tcp_fastopen)) {
93 return false; 96 return false;
94 } 97 }
95 // The read from /proc should return '1' if TCP FastOpen is enabled in the OS. 98 // The read value from /proc will be set in its least significant bit if
96 if (system_supports_tcp_fastopen.empty() || 99 // TCP FastOpen is enabled.
97 (system_supports_tcp_fastopen[0] != '1')) { 100 int read_int = 0;
98 return false; 101 base::StringToInt(
99 } 102 HttpUtil::TrimLWS(base::StringPiece(system_supports_tcp_fastopen)),
100 return true; 103 &read_int);
104 if ((read_int & 0x1) == 1)
105 return true;
106 return false;
101 } 107 }
102 108
103 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled, 109 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled,
104 bool system_supported) { 110 bool system_supported) {
105 g_tcp_fastopen_supported = system_supported; 111 g_tcp_fastopen_supported = system_supported;
106 g_tcp_fastopen_user_enabled = user_enabled; 112 g_tcp_fastopen_user_enabled = user_enabled;
107 } 113 }
108 #endif 114 #endif
109 115
110 #if defined(TCP_INFO) 116 #if defined(TCP_INFO)
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 if (info.tcpi_rtt > 0) { 800 if (info.tcpi_rtt > 0) {
795 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); 801 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt);
796 return true; 802 return true;
797 } 803 }
798 } 804 }
799 #endif // defined(TCP_INFO) 805 #endif // defined(TCP_INFO)
800 return false; 806 return false;
801 } 807 }
802 808
803 } // namespace net 809 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698