diff options
author | ricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 10:57:22 +0000 |
---|---|---|
committer | ricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 10:57:22 +0000 |
commit | 3fe57da4f047d7b07589434c13aa1aa970039590 (patch) | |
tree | 2d8d92e59813791dd3c48bb6930d6025a2c13a86 | |
parent | 04ddc345ce9cfa8e19cc36a9c3913eea194c2984 (diff) | |
download | chromium_src-3fe57da4f047d7b07589434c13aa1aa970039590.zip chromium_src-3fe57da4f047d7b07589434c13aa1aa970039590.tar.gz chromium_src-3fe57da4f047d7b07589434c13aa1aa970039590.tar.bz2 |
Avoid error in debug builds with TCP FastOpen
TCP FastOpen checks the contents of the file
/proc/sys/net/ipv4/tcp_fastopen to see whether the kernel supports TCP
FastOpen. It did this on the IO thread, which caused an abort on debug
builds.
Make the check asynchronous and perform it on the worker pool instead.
BUG=365649
TEST=net_unittests, chrome debug build
Review URL: https://codereview.chromium.org/247093003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267172 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/socket/tcp_socket.cc | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/net/socket/tcp_socket.cc b/net/socket/tcp_socket.cc index f7eced9..6370362 100644 --- a/net/socket/tcp_socket.cc +++ b/net/socket/tcp_socket.cc @@ -6,50 +6,73 @@ #include "base/file_util.h" #include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/threading/worker_pool.h" namespace net { namespace { +bool g_tcp_fastopen_enabled = false; + #if defined(OS_LINUX) || defined(OS_ANDROID) +typedef base::RefCountedData<bool> SharedBoolean; + // Checks to see if the system supports TCP FastOpen. Notably, it requires // kernel support. Additionally, this checks system configuration to ensure that // it's enabled. -bool SystemSupportsTCPFastOpen() { +void SystemSupportsTCPFastOpen(scoped_refptr<SharedBoolean> supported) { + supported->data = false; static const base::FilePath::CharType kTCPFastOpenProcFilePath[] = "/proc/sys/net/ipv4/tcp_fastopen"; std::string system_enabled_tcp_fastopen; - if (!base::ReadFileToString( - base::FilePath(kTCPFastOpenProcFilePath), - &system_enabled_tcp_fastopen)) { - return false; + if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath), + &system_enabled_tcp_fastopen)) { + return; } // As per http://lxr.linux.no/linux+v3.7.7/include/net/tcp.h#L225 // TFO_CLIENT_ENABLE is the LSB if (system_enabled_tcp_fastopen.empty() || (system_enabled_tcp_fastopen[0] & 0x1) == 0) { - return false; + return; } - return true; + supported->data = true; +} + +void EnableCallback(scoped_refptr<SharedBoolean> supported) { + g_tcp_fastopen_enabled = supported->data; +} + +// This is asynchronous because it needs to do file IO, and it isn't allowed to +// do that on the IO thread. +void EnableFastOpenIfSupported() { + scoped_refptr<SharedBoolean> supported = new SharedBoolean; + base::WorkerPool::PostTaskAndReply( + FROM_HERE, + base::Bind(SystemSupportsTCPFastOpen, supported), + base::Bind(EnableCallback, supported), + false); } #else -bool SystemSupportsTCPFastOpen() { - return false; +void EnableFastOpenIfSupported() { + g_tcp_fastopen_enabled = false; } #endif -bool g_tcp_fastopen_enabled = false; - } // namespace void SetTCPFastOpenEnabled(bool value) { - g_tcp_fastopen_enabled = value && SystemSupportsTCPFastOpen(); + if (value) { + EnableFastOpenIfSupported(); + } else { + g_tcp_fastopen_enabled = false; + } } bool IsTCPFastOpenEnabled() { |