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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 const IPEndPoint& endpoint = addresses_[current_address_index_]; | 118 const IPEndPoint& endpoint = addresses_[current_address_index_]; |
119 | 119 |
120 { | 120 { |
121 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | 121 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. |
122 tracked_objects::ScopedTracker tracking_profile( | 122 tracked_objects::ScopedTracker tracking_profile( |
123 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 TCPClientSocket::DoConnect")); | 123 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 TCPClientSocket::DoConnect")); |
124 | 124 |
125 if (previously_disconnected_) { | 125 if (previously_disconnected_) { |
126 use_history_.Reset(); | 126 use_history_.Reset(); |
| 127 connection_attempts_.clear(); |
127 previously_disconnected_ = false; | 128 previously_disconnected_ = false; |
128 } | 129 } |
129 | 130 |
130 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; | 131 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; |
131 | 132 |
132 if (socket_->IsValid()) { | 133 if (socket_->IsValid()) { |
133 DCHECK(bind_address_); | 134 DCHECK(bind_address_); |
134 } else { | 135 } else { |
135 int result = OpenSocket(endpoint.GetFamily()); | 136 int result = OpenSocket(endpoint.GetFamily()); |
136 if (result != OK) | 137 if (result != OK) |
(...skipping 15 matching lines...) Expand all Loading... |
152 base::Bind(&TCPClientSocket::DidCompleteConnect, | 153 base::Bind(&TCPClientSocket::DidCompleteConnect, |
153 base::Unretained(this))); | 154 base::Unretained(this))); |
154 } | 155 } |
155 | 156 |
156 int TCPClientSocket::DoConnectComplete(int result) { | 157 int TCPClientSocket::DoConnectComplete(int result) { |
157 if (result == OK) { | 158 if (result == OK) { |
158 use_history_.set_was_ever_connected(); | 159 use_history_.set_was_ever_connected(); |
159 return OK; // Done! | 160 return OK; // Done! |
160 } | 161 } |
161 | 162 |
| 163 connection_attempts_.push_back( |
| 164 ConnectionAttempt(addresses_[current_address_index_], result)); |
| 165 |
162 // Close whatever partially connected socket we currently have. | 166 // Close whatever partially connected socket we currently have. |
163 DoDisconnect(); | 167 DoDisconnect(); |
164 | 168 |
165 // Try to fall back to the next address in the list. | 169 // Try to fall back to the next address in the list. |
166 if (current_address_index_ + 1 < static_cast<int>(addresses_.size())) { | 170 if (current_address_index_ + 1 < static_cast<int>(addresses_.size())) { |
167 next_connect_state_ = CONNECT_STATE_CONNECT; | 171 next_connect_state_ = CONNECT_STATE_CONNECT; |
168 ++current_address_index_; | 172 ++current_address_index_; |
169 return OK; | 173 return OK; |
170 } | 174 } |
171 | 175 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 293 } |
290 | 294 |
291 bool TCPClientSocket::SetKeepAlive(bool enable, int delay) { | 295 bool TCPClientSocket::SetKeepAlive(bool enable, int delay) { |
292 return socket_->SetKeepAlive(enable, delay); | 296 return socket_->SetKeepAlive(enable, delay); |
293 } | 297 } |
294 | 298 |
295 bool TCPClientSocket::SetNoDelay(bool no_delay) { | 299 bool TCPClientSocket::SetNoDelay(bool no_delay) { |
296 return socket_->SetNoDelay(no_delay); | 300 return socket_->SetNoDelay(no_delay); |
297 } | 301 } |
298 | 302 |
| 303 void TCPClientSocket::GetConnectionAttempts(ConnectionAttempts* out) const { |
| 304 *out = connection_attempts_; |
| 305 } |
| 306 |
| 307 void TCPClientSocket::ClearConnectionAttempts() { |
| 308 connection_attempts_.clear(); |
| 309 } |
| 310 |
| 311 void TCPClientSocket::AddConnectionAttempts( |
| 312 const ConnectionAttempts& attempts) { |
| 313 connection_attempts_.insert(connection_attempts_.begin(), attempts.begin(), |
| 314 attempts.end()); |
| 315 } |
| 316 |
299 void TCPClientSocket::DidCompleteConnect(int result) { | 317 void TCPClientSocket::DidCompleteConnect(int result) { |
300 DCHECK_EQ(next_connect_state_, CONNECT_STATE_CONNECT_COMPLETE); | 318 DCHECK_EQ(next_connect_state_, CONNECT_STATE_CONNECT_COMPLETE); |
301 DCHECK_NE(result, ERR_IO_PENDING); | 319 DCHECK_NE(result, ERR_IO_PENDING); |
302 DCHECK(!connect_callback_.is_null()); | 320 DCHECK(!connect_callback_.is_null()); |
303 | 321 |
304 result = DoConnectLoop(result); | 322 result = DoConnectLoop(result); |
305 if (result != ERR_IO_PENDING) { | 323 if (result != ERR_IO_PENDING) { |
306 socket_->EndLoggingMultipleConnectAttempts(result); | 324 socket_->EndLoggingMultipleConnectAttempts(result); |
307 base::ResetAndReturn(&connect_callback_).Run(result); | 325 base::ResetAndReturn(&connect_callback_).Run(result); |
308 } | 326 } |
(...skipping 17 matching lines...) Expand all Loading... |
326 int result = socket_->Open(family); | 344 int result = socket_->Open(family); |
327 if (result != OK) | 345 if (result != OK) |
328 return result; | 346 return result; |
329 | 347 |
330 socket_->SetDefaultOptionsForClient(); | 348 socket_->SetDefaultOptionsForClient(); |
331 | 349 |
332 return OK; | 350 return OK; |
333 } | 351 } |
334 | 352 |
335 } // namespace net | 353 } // namespace net |
OLD | NEW |