Index: net/socket/tcp_socket.cc |
diff --git a/net/socket/tcp_socket.cc b/net/socket/tcp_socket.cc |
index 864159750a8d2c700af63ff7692633dac7e50453..ba62b149c57f35be3b4d069c50d5131b07771a95 100644 |
--- a/net/socket/tcp_socket.cc |
+++ b/net/socket/tcp_socket.cc |
@@ -14,66 +14,62 @@ namespace net { |
namespace { |
+// True if OS supports TCP FastOpen. |
+bool g_tcp_fastopen_supported = false; |
+// True if OS supports TCP FastOpen and is turned on for all connections. |
bool g_tcp_fastopen_enabled = false; |
mmenke
2014/08/12 15:25:15
Do we really need globals for TCP FastOpen? May t
Jana
2014/08/13 07:33:40
I'll see how this might be done. Given that this c
mmenke
2014/08/13 15:36:49
Fine with a TODO, for now, though I suspect that m
|
#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. |
-void SystemSupportsTCPFastOpen(scoped_refptr<SharedBoolean> supported) { |
- supported->data = false; |
+// Checks if the kernel supports TCP FastOpen. |
+void SystemSupportsTCPFastOpen(scoped_refptr<SharedBoolean> system_supported) { |
+ system_supported->data = false; |
static const base::FilePath::CharType kTCPFastOpenProcFilePath[] = |
"/proc/sys/net/ipv4/tcp_fastopen"; |
- std::string system_enabled_tcp_fastopen; |
+ std::string system_supports_tcp_fastopen; |
if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath), |
- &system_enabled_tcp_fastopen)) { |
+ &system_supports_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) { |
+ // The read from /proc should return '1' if TCP FastOpen is enabled in the OS. |
+ if (system_supports_tcp_fastopen.empty() || |
+ (system_supports_tcp_fastopen[0] != '1')) { |
return; |
} |
- |
- supported->data = true; |
+ system_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); |
+void CallbackForTCPFastOpenCheck(scoped_refptr<SharedBoolean> system_supported, |
+ bool user_enabled) { |
+ g_tcp_fastopen_supported = system_supported->data; |
+ if (user_enabled) { |
+ g_tcp_fastopen_enabled = system_supported->data; |
+ } |
} |
#else |
-void EnableFastOpenIfSupported() { |
- g_tcp_fastopen_enabled = false; |
-} |
+void CheckSupportAndMaybeEnableTCPFastOpen(bool user_enabled) {} |
#endif |
} // namespace |
-void SetTCPFastOpenEnabled(bool value) { |
- if (value) { |
- EnableFastOpenIfSupported(); |
- } else { |
- g_tcp_fastopen_enabled = false; |
- } |
+// This is asynchronous because it needs to do file IO, and it isn't allowed to |
+// do that on the IO thread. |
+void CheckSupportAndMaybeEnableTCPFastOpen(bool user_enabled) { |
+ scoped_refptr<SharedBoolean> system_supported = new SharedBoolean; |
mmenke
2014/08/12 15:25:15
Using a shared boolean seems unnecessary to me. Y
Jana
2014/08/13 07:33:40
Done.
|
+ base::WorkerPool::PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(SystemSupportsTCPFastOpen, system_supported), |
+ base::Bind(CallbackForTCPFastOpenCheck, system_supported, user_enabled), |
+ false); |
+} |
+ |
+bool IsTCPFastOpenSupported() { |
+ return g_tcp_fastopen_supported; |
} |
bool IsTCPFastOpenEnabled() { |