OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_client_socket.h" | 5 #include "net/socket/tcp_client_socket.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/file_util.h" | |
9 #include "base/files/file_path.h" | |
10 #include "base/logging.h" | 8 #include "base/logging.h" |
11 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
12 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
13 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
15 | 13 |
16 namespace net { | 14 namespace net { |
17 | 15 |
18 namespace { | |
19 | |
20 #if defined(OS_LINUX) | |
21 | |
22 // Checks to see if the system supports TCP FastOpen. Notably, it requires | |
23 // kernel support. Additionally, this checks system configuration to ensure that | |
24 // it's enabled. | |
25 bool SystemSupportsTCPFastOpen() { | |
26 static const base::FilePath::CharType kTCPFastOpenProcFilePath[] = | |
27 "/proc/sys/net/ipv4/tcp_fastopen"; | |
28 std::string system_enabled_tcp_fastopen; | |
29 if (!base::ReadFileToString( | |
30 base::FilePath(kTCPFastOpenProcFilePath), | |
31 &system_enabled_tcp_fastopen)) { | |
32 return false; | |
33 } | |
34 | |
35 // As per http://lxr.linux.no/linux+v3.7.7/include/net/tcp.h#L225 | |
36 // TFO_CLIENT_ENABLE is the LSB | |
37 if (system_enabled_tcp_fastopen.empty() || | |
38 (system_enabled_tcp_fastopen[0] & 0x1) == 0) { | |
39 return false; | |
40 } | |
41 | |
42 return true; | |
43 } | |
44 | |
45 #else | |
46 | |
47 bool SystemSupportsTCPFastOpen() { | |
48 return false; | |
49 } | |
50 | |
51 #endif | |
52 | |
53 } | |
54 | |
55 static bool g_tcp_fastopen_enabled = false; | |
56 | |
57 void SetTCPFastOpenEnabled(bool value) { | |
58 g_tcp_fastopen_enabled = value && SystemSupportsTCPFastOpen(); | |
59 } | |
60 | |
61 bool IsTCPFastOpenEnabled() { | |
62 return g_tcp_fastopen_enabled; | |
63 } | |
64 | |
65 #if defined(OS_WIN) | |
66 | |
67 TCPClientSocket::TCPClientSocket(const AddressList& addresses, | 16 TCPClientSocket::TCPClientSocket(const AddressList& addresses, |
68 net::NetLog* net_log, | 17 net::NetLog* net_log, |
69 const net::NetLog::Source& source) | 18 const net::NetLog::Source& source) |
70 : socket_(new TCPSocket(net_log, source)), | 19 : socket_(new TCPSocket(net_log, source)), |
71 addresses_(addresses), | 20 addresses_(addresses), |
72 current_address_index_(-1), | 21 current_address_index_(-1), |
73 next_connect_state_(CONNECT_STATE_NONE), | 22 next_connect_state_(CONNECT_STATE_NONE), |
74 previously_disconnected_(false) { | 23 previously_disconnected_(false) { |
75 } | 24 } |
76 | 25 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 310 |
362 int result = socket_->Open(family); | 311 int result = socket_->Open(family); |
363 if (result != OK) | 312 if (result != OK) |
364 return result; | 313 return result; |
365 | 314 |
366 socket_->SetDefaultOptionsForClient(); | 315 socket_->SetDefaultOptionsForClient(); |
367 | 316 |
368 return OK; | 317 return OK; |
369 } | 318 } |
370 | 319 |
371 #endif | |
372 | |
373 } // namespace net | 320 } // namespace net |
OLD | NEW |