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

Unified Diff: net/socket/tcp_socket_libevent.cc

Issue 451383002: Plumbing for TCP FastOpen for SSL sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved TFO enabling to client_socket_pool_manager and cleaned up tcp_socket.cc (added tcp_socket.cc … Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: net/socket/tcp_socket_libevent.cc
diff --git a/net/socket/tcp_socket_libevent.cc b/net/socket/tcp_socket_libevent.cc
index 444e3c04231ce3f5279e56dad7e43d557d7bc86e..76a113a61970ff4775af1a345aa8c4f0827554ba 100644
--- a/net/socket/tcp_socket_libevent.cc
+++ b/net/socket/tcp_socket_libevent.cc
@@ -13,6 +13,8 @@
#include "base/metrics/histogram.h"
#include "base/metrics/stats_counters.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/task_runner_util.h"
+#include "base/threading/worker_pool.h"
#include "net/base/address_list.h"
#include "net/base/connection_type_histograms.h"
#include "net/base/io_buffer.h"
@@ -28,6 +30,12 @@
#define TCPI_OPT_SYN_DATA 32
#endif
+// 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.
+// TODO(jri): Change global variable to param in HttpNetworkSession::Params.
+bool g_tcp_fastopen_enabled = false;
+
namespace net {
namespace {
@@ -69,10 +77,59 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) {
return true;
}
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+// Checks if the kernel supports TCP FastOpen.
+bool SystemSupportsTCPFastOpen() {
+ static const base::FilePath::CharType kTCPFastOpenProcFilePath[] =
+ "/proc/sys/net/ipv4/tcp_fastopen";
+ std::string system_supports_tcp_fastopen;
+ if (!base::ReadFileToString(base::FilePath(kTCPFastOpenProcFilePath),
+ &system_supports_tcp_fastopen)) {
+ return false;
+ }
+ // 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 false;
+ }
+ return true;
+}
+
+void CallbackForTCPFastOpenCheck(bool user_enabled,
+ bool system_supported) {
+ g_tcp_fastopen_supported = system_supported;
+ if (user_enabled) {
+ g_tcp_fastopen_enabled = system_supported;
+ }
+}
+#endif
+
+// Check if TCP FastOpen option is supported by the OS.
+bool IsTCPFastOpenSupported() {
+ return g_tcp_fastopen_supported;
+}
+
+// Check if TCP FastOpen option is enabled.
+bool IsTCPFastOpenEnabled() {
+ return g_tcp_fastopen_enabled;
+}
+
} // namespace
//-----------------------------------------------------------------------------
+// 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) {
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+ base::PostTaskAndReplyWithResult(
+ base::WorkerPool::GetTaskRunner(/*task_is_slow=*/false),
+ FROM_HERE,
+ base::Bind(SystemSupportsTCPFastOpen),
+ base::Bind(CallbackForTCPFastOpenCheck, user_enabled));
+#endif
+}
+
TCPSocketLibevent::TCPSocketLibevent(NetLog* net_log,
const NetLog::Source& source)
: use_tcp_fastopen_(IsTCPFastOpenEnabled()),
@@ -369,6 +426,11 @@ bool TCPSocketLibevent::UsingTCPFastOpen() const {
return use_tcp_fastopen_;
}
+void TCPSocketLibevent::EnableTCPFastOpen() {
+ if (!use_tcp_fastopen_ && IsTCPFastOpenSupported())
+ use_tcp_fastopen_ = true;
+}
+
bool TCPSocketLibevent::IsValid() const {
return socket_ != NULL && socket_->socket_fd() != kInvalidSocket;
}
@@ -495,7 +557,7 @@ void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf,
const CompletionCallback& callback,
int rv) {
DCHECK_NE(ERR_IO_PENDING, rv);
- // Records fast open status regardless of error in asynchronous case.
+ // Records TCP FastOpen status regardless of error in asynchronous case.
// TODO(rdsmith,jri): Change histogram name to indicate it could be called on
// error.
RecordFastOpenStatus();
@@ -597,7 +659,7 @@ void TCPSocketLibevent::RecordFastOpenStatus() {
bool getsockopt_success(false);
bool server_acked_data(false);
#if defined(TCP_INFO)
- // Probe to see the if the socket used TCP Fast Open.
+ // Probe to see the if the socket used TCP FastOpen.
tcp_info info;
socklen_t info_len = sizeof(tcp_info);
getsockopt_success =

Powered by Google App Engine
This is Rietveld 408576698