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

Side by Side Diff: net/socket/tcp_client_socket.cc

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « net/socket/ssl_client_socket_openssl_unittest.cc ('k') | net/socket/tcp_socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 result = socket_->Bind(address); 57 result = socket_->Bind(address);
58 if (result != OK) 58 if (result != OK)
59 return result; 59 return result;
60 60
61 bind_address_.reset(new IPEndPoint(address)); 61 bind_address_.reset(new IPEndPoint(address));
62 return OK; 62 return OK;
63 } 63 }
64 64
65 int TCPClientSocket::Connect(const CompletionCallback& callback) { 65 int TCPClientSocket::Connect(const CompletionCallback& callback) {
66 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed.
67 tracked_objects::ScopedTracker tracking_profile(
68 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 TCPClientSocket::Connect"));
69
66 DCHECK(!callback.is_null()); 70 DCHECK(!callback.is_null());
67 71
68 // If connecting or already connected, then just return OK. 72 // If connecting or already connected, then just return OK.
69 if (socket_->IsValid() && current_address_index_ >= 0) 73 if (socket_->IsValid() && current_address_index_ >= 0)
70 return OK; 74 return OK;
71 75
72 socket_->StartLoggingMultipleConnectAttempts(addresses_); 76 socket_->StartLoggingMultipleConnectAttempts(addresses_);
73 77
74 // We will try to connect to each address in addresses_. Start with the 78 // We will try to connect to each address in addresses_. Start with the
75 // first one in the list. 79 // first one in the list.
(...skipping 29 matching lines...) Expand all
105 NOTREACHED() << "bad state " << state; 109 NOTREACHED() << "bad state " << state;
106 rv = ERR_UNEXPECTED; 110 rv = ERR_UNEXPECTED;
107 break; 111 break;
108 } 112 }
109 } while (rv != ERR_IO_PENDING && next_connect_state_ != CONNECT_STATE_NONE); 113 } while (rv != ERR_IO_PENDING && next_connect_state_ != CONNECT_STATE_NONE);
110 114
111 return rv; 115 return rv;
112 } 116 }
113 117
114 int TCPClientSocket::DoConnect() { 118 int TCPClientSocket::DoConnect() {
119 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed.
120 tracked_objects::ScopedTracker tracking_profile1(
121 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 TCPClientSocket::DoConnect1"));
122
115 DCHECK_GE(current_address_index_, 0); 123 DCHECK_GE(current_address_index_, 0);
116 DCHECK_LT(current_address_index_, static_cast<int>(addresses_.size())); 124 DCHECK_LT(current_address_index_, static_cast<int>(addresses_.size()));
117 125
118 const IPEndPoint& endpoint = addresses_[current_address_index_]; 126 const IPEndPoint& endpoint = addresses_[current_address_index_];
119 127
120 if (previously_disconnected_) { 128 if (previously_disconnected_) {
121 use_history_.Reset(); 129 use_history_.Reset();
122 previously_disconnected_ = false; 130 previously_disconnected_ = false;
123 } 131 }
124 132
125 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; 133 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE;
126 134
127 if (socket_->IsValid()) { 135 if (socket_->IsValid()) {
128 DCHECK(bind_address_); 136 DCHECK(bind_address_);
129 } else { 137 } else {
130 int result = OpenSocket(endpoint.GetFamily()); 138 int result = OpenSocket(endpoint.GetFamily());
131 if (result != OK) 139 if (result != OK)
132 return result; 140 return result;
133 141
134 if (bind_address_) { 142 if (bind_address_) {
135 result = socket_->Bind(*bind_address_); 143 result = socket_->Bind(*bind_address_);
136 if (result != OK) { 144 if (result != OK) {
137 socket_->Close(); 145 socket_->Close();
138 return result; 146 return result;
139 } 147 }
140 } 148 }
141 } 149 }
142 150
151 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed.
152 tracked_objects::ScopedTracker tracking_profile2(
153 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 TCPClientSocket::DoConnect2"));
154
143 // |socket_| is owned by this class and the callback won't be run once 155 // |socket_| is owned by this class and the callback won't be run once
144 // |socket_| is gone. Therefore, it is safe to use base::Unretained() here. 156 // |socket_| is gone. Therefore, it is safe to use base::Unretained() here.
145 return socket_->Connect(endpoint, 157 return socket_->Connect(endpoint,
146 base::Bind(&TCPClientSocket::DidCompleteConnect, 158 base::Bind(&TCPClientSocket::DidCompleteConnect,
147 base::Unretained(this))); 159 base::Unretained(this)));
148 } 160 }
149 161
150 int TCPClientSocket::DoConnectComplete(int result) { 162 int TCPClientSocket::DoConnectComplete(int result) {
163 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed.
164 tracked_objects::ScopedTracker tracking_profile(
165 FROM_HERE_WITH_EXPLICIT_FUNCTION(
166 "436634 TCPClientSocket::DoConnectComplete"));
167
151 if (result == OK) { 168 if (result == OK) {
152 use_history_.set_was_ever_connected(); 169 use_history_.set_was_ever_connected();
153 return OK; // Done! 170 return OK; // Done!
154 } 171 }
155 172
156 // Close whatever partially connected socket we currently have. 173 // Close whatever partially connected socket we currently have.
157 DoDisconnect(); 174 DoDisconnect();
158 175
159 // Try to fall back to the next address in the list. 176 // Try to fall back to the next address in the list.
160 if (current_address_index_ + 1 < static_cast<int>(addresses_.size())) { 177 if (current_address_index_ + 1 < static_cast<int>(addresses_.size())) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 int result = socket_->Open(family); 337 int result = socket_->Open(family);
321 if (result != OK) 338 if (result != OK)
322 return result; 339 return result;
323 340
324 socket_->SetDefaultOptionsForClient(); 341 socket_->SetDefaultOptionsForClient();
325 342
326 return OK; 343 return OK;
327 } 344 }
328 345
329 } // namespace net 346 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_openssl_unittest.cc ('k') | net/socket/tcp_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698