Chromium Code Reviews| 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/metrics/histogram_macros.h" | |
| 9 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| 11 #include "base/time/time.h" | |
| 10 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 11 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 13 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 | 18 |
| 17 TCPClientSocket::TCPClientSocket(const AddressList& addresses, | 19 TCPClientSocket::TCPClientSocket(const AddressList& addresses, |
| 18 net::NetLog* net_log, | 20 net::NetLog* net_log, |
| 19 const net::NetLog::Source& source) | 21 const net::NetLog::Source& source) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 31 current_address_index_(0), | 33 current_address_index_(0), |
| 32 next_connect_state_(CONNECT_STATE_NONE), | 34 next_connect_state_(CONNECT_STATE_NONE), |
| 33 previously_disconnected_(false) { | 35 previously_disconnected_(false) { |
| 34 DCHECK(socket_); | 36 DCHECK(socket_); |
| 35 | 37 |
| 36 socket_->SetDefaultOptionsForClient(); | 38 socket_->SetDefaultOptionsForClient(); |
| 37 use_history_.set_was_ever_connected(); | 39 use_history_.set_was_ever_connected(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 TCPClientSocket::~TCPClientSocket() { | 42 TCPClientSocket::~TCPClientSocket() { |
| 43 Disconnect(); | |
| 41 } | 44 } |
| 42 | 45 |
| 43 int TCPClientSocket::Bind(const IPEndPoint& address) { | 46 int TCPClientSocket::Bind(const IPEndPoint& address) { |
| 44 if (current_address_index_ >= 0 || bind_address_) { | 47 if (current_address_index_ >= 0 || bind_address_) { |
| 45 // Cannot bind the socket if we are already connected or connecting. | 48 // Cannot bind the socket if we are already connected or connecting. |
| 46 NOTREACHED(); | 49 NOTREACHED(); |
| 47 return ERR_UNEXPECTED; | 50 return ERR_UNEXPECTED; |
| 48 } | 51 } |
| 49 | 52 |
| 50 int result = OK; | 53 int result = OK; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 if (current_address_index_ + 1 < static_cast<int>(addresses_.size())) { | 173 if (current_address_index_ + 1 < static_cast<int>(addresses_.size())) { |
| 171 next_connect_state_ = CONNECT_STATE_CONNECT; | 174 next_connect_state_ = CONNECT_STATE_CONNECT; |
| 172 ++current_address_index_; | 175 ++current_address_index_; |
| 173 return OK; | 176 return OK; |
| 174 } | 177 } |
| 175 | 178 |
| 176 // Otherwise there is nothing to fall back to, so give up. | 179 // Otherwise there is nothing to fall back to, so give up. |
| 177 return result; | 180 return result; |
| 178 } | 181 } |
| 179 | 182 |
| 180 void TCPClientSocket::Disconnect() { | 183 void TCPClientSocket::Disconnect() { |
|
mmenke
2015/07/07 21:27:29
This is a valid concern. While I suspect we'll se
Bryan McQuade
2015/07/08 00:35:37
I'm ok leaving this as-is for the time being. To r
| |
| 181 DoDisconnect(); | 184 DoDisconnect(); |
| 182 current_address_index_ = -1; | 185 current_address_index_ = -1; |
| 183 bind_address_.reset(); | 186 bind_address_.reset(); |
| 184 } | 187 } |
| 185 | 188 |
| 186 void TCPClientSocket::DoDisconnect() { | 189 void TCPClientSocket::DoDisconnect() { |
| 190 EmitTCPMetricsHistogramsOnDisconnect(); | |
| 187 // If connecting or already connected, record that the socket has been | 191 // If connecting or already connected, record that the socket has been |
| 188 // disconnected. | 192 // disconnected. |
| 189 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; | 193 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; |
| 190 socket_->Close(); | 194 socket_->Close(); |
| 191 } | 195 } |
| 192 | 196 |
| 193 bool TCPClientSocket::IsConnected() const { | 197 bool TCPClientSocket::IsConnected() const { |
| 194 return socket_->IsConnected(); | 198 return socket_->IsConnected(); |
| 195 } | 199 } |
| 196 | 200 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 | 347 |
| 344 int result = socket_->Open(family); | 348 int result = socket_->Open(family); |
| 345 if (result != OK) | 349 if (result != OK) |
| 346 return result; | 350 return result; |
| 347 | 351 |
| 348 socket_->SetDefaultOptionsForClient(); | 352 socket_->SetDefaultOptionsForClient(); |
| 349 | 353 |
| 350 return OK; | 354 return OK; |
| 351 } | 355 } |
| 352 | 356 |
| 357 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { | |
| 358 base::TimeDelta rtt; | |
| 359 if (socket_->GetEstimatedRoundTripTime(&rtt)) { | |
| 360 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, | |
| 361 base::TimeDelta::FromMilliseconds(1), | |
| 362 base::TimeDelta::FromMinutes(10), 100); | |
| 363 } | |
| 364 } | |
| 365 | |
| 353 } // namespace net | 366 } // namespace net |
| OLD | NEW |