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/file_util.h" | |
8 #include "base/files/file_path.h" | |
9 | |
10 #if defined(OS_WIN) | |
11 | |
12 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
13 #include "net/base/ip_endpoint.h" | 8 #include "net/base/ip_endpoint.h" |
14 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
15 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
16 | 11 |
17 #endif | |
18 | |
19 namespace net { | 12 namespace net { |
20 | 13 |
21 namespace { | |
22 | |
23 #if defined(OS_LINUX) | |
24 | |
25 // Checks to see if the system supports TCP FastOpen. Notably, it requires | |
26 // kernel support. Additionally, this checks system configuration to ensure that | |
27 // it's enabled. | |
28 bool SystemSupportsTCPFastOpen() { | |
29 static const base::FilePath::CharType kTCPFastOpenProcFilePath[] = | |
30 "/proc/sys/net/ipv4/tcp_fastopen"; | |
31 std::string system_enabled_tcp_fastopen; | |
32 if (!base::ReadFileToString( | |
33 base::FilePath(kTCPFastOpenProcFilePath), | |
34 &system_enabled_tcp_fastopen)) { | |
35 return false; | |
36 } | |
37 | |
38 // As per http://lxr.linux.no/linux+v3.7.7/include/net/tcp.h#L225 | |
39 // TFO_CLIENT_ENABLE is the LSB | |
40 if (system_enabled_tcp_fastopen.empty() || | |
41 (system_enabled_tcp_fastopen[0] & 0x1) == 0) { | |
42 return false; | |
43 } | |
44 | |
45 return true; | |
46 } | |
47 | |
48 #else | |
49 | |
50 bool SystemSupportsTCPFastOpen() { | |
51 return false; | |
52 } | |
53 | |
54 #endif | |
55 | |
56 } | |
57 | |
58 static bool g_tcp_fastopen_enabled = false; | |
59 | |
60 void SetTCPFastOpenEnabled(bool value) { | |
61 g_tcp_fastopen_enabled = value && SystemSupportsTCPFastOpen(); | |
62 } | |
63 | |
64 bool IsTCPFastOpenEnabled() { | |
65 return g_tcp_fastopen_enabled; | |
66 } | |
67 | |
68 #if defined(OS_WIN) | |
69 | |
70 TCPClientSocket::TCPClientSocket(const AddressList& addresses, | 14 TCPClientSocket::TCPClientSocket(const AddressList& addresses, |
71 net::NetLog* net_log, | 15 net::NetLog* net_log, |
72 const net::NetLog::Source& source) | 16 const net::NetLog::Source& source) |
73 : socket_(new TCPSocket(net_log, source)), | 17 : socket_(new TCPSocket(net_log, source)), |
74 addresses_(addresses), | 18 addresses_(addresses), |
75 current_address_index_(-1), | 19 current_address_index_(-1), |
76 next_connect_state_(CONNECT_STATE_NONE), | 20 next_connect_state_(CONNECT_STATE_NONE), |
77 previously_disconnected_(false) { | 21 previously_disconnected_(false) { |
78 } | 22 } |
79 | 23 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (bind_address_.get()) { | 196 if (bind_address_.get()) { |
253 *address = *bind_address_; | 197 *address = *bind_address_; |
254 return OK; | 198 return OK; |
255 } | 199 } |
256 return ERR_SOCKET_NOT_CONNECTED; | 200 return ERR_SOCKET_NOT_CONNECTED; |
257 } | 201 } |
258 | 202 |
259 return socket_->GetLocalAddress(address); | 203 return socket_->GetLocalAddress(address); |
260 } | 204 } |
261 | 205 |
| 206 const BoundNetLog& TCPClientSocket::NetLog() const { |
| 207 return socket_->net_log(); |
| 208 } |
| 209 |
262 void TCPClientSocket::SetSubresourceSpeculation() { | 210 void TCPClientSocket::SetSubresourceSpeculation() { |
263 use_history_.set_subresource_speculation(); | 211 use_history_.set_subresource_speculation(); |
264 } | 212 } |
265 | 213 |
266 void TCPClientSocket::SetOmniboxSpeculation() { | 214 void TCPClientSocket::SetOmniboxSpeculation() { |
267 use_history_.set_omnibox_speculation(); | 215 use_history_.set_omnibox_speculation(); |
268 } | 216 } |
269 | 217 |
270 bool TCPClientSocket::WasEverUsed() const { | 218 bool TCPClientSocket::WasEverUsed() const { |
271 return use_history_.was_used_to_convey_data(); | 219 return use_history_.was_used_to_convey_data(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 if (result != OK) | 307 if (result != OK) |
360 return result; | 308 return result; |
361 | 309 |
362 result = socket_->SetDefaultOptionsForClient(); | 310 result = socket_->SetDefaultOptionsForClient(); |
363 if (result != OK) | 311 if (result != OK) |
364 socket_->Close(); | 312 socket_->Close(); |
365 | 313 |
366 return result; | 314 return result; |
367 } | 315 } |
368 | 316 |
369 #endif | |
370 | |
371 } // namespace net | 317 } // namespace net |
OLD | NEW |