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

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

Issue 344026: Add LoadLog to ClientSocket::Connect(). (Closed)
Patch Set: Minor build fixups and fixed mac bug. Created 11 years, 1 month 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/socks_client_socket.h ('k') | net/socket/socks_client_socket_unittest.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/socks_client_socket.h" 5 #include "net/socket/socks_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <ws2tcpip.h> 10 #include <ws2tcpip.h>
11 #elif defined(OS_POSIX) 11 #elif defined(OS_POSIX)
12 #include <netdb.h> 12 #include <netdb.h>
13 #endif 13 #endif
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/trace_event.h" 15 #include "base/trace_event.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/load_log.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 // Every SOCKS server requests a user-id from the client. It is optional 22 // Every SOCKS server requests a user-id from the client. It is optional
22 // and we send an empty string. 23 // and we send an empty string.
23 static const char kEmptyUserId[] = ""; 24 static const char kEmptyUserId[] = "";
24 25
25 // The SOCKS4a implementation suggests to use an invalid IP in case the DNS 26 // The SOCKS4a implementation suggests to use an invalid IP in case the DNS
26 // resolution at client fails. 27 // resolution at client fails.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 bytes_sent_(0), 77 bytes_sent_(0),
77 bytes_received_(0), 78 bytes_received_(0),
78 host_resolver_(host_resolver), 79 host_resolver_(host_resolver),
79 host_request_info_(req_info) { 80 host_request_info_(req_info) {
80 } 81 }
81 82
82 SOCKSClientSocket::~SOCKSClientSocket() { 83 SOCKSClientSocket::~SOCKSClientSocket() {
83 Disconnect(); 84 Disconnect();
84 } 85 }
85 86
86 int SOCKSClientSocket::Connect(CompletionCallback* callback) { 87 int SOCKSClientSocket::Connect(CompletionCallback* callback,
88 LoadLog* load_log) {
87 DCHECK(transport_.get()); 89 DCHECK(transport_.get());
88 DCHECK(transport_->IsConnected()); 90 DCHECK(transport_->IsConnected());
89 DCHECK_EQ(STATE_NONE, next_state_); 91 DCHECK_EQ(STATE_NONE, next_state_);
90 DCHECK(!user_callback_); 92 DCHECK(!user_callback_);
91 93
92 // If already connected, then just return OK. 94 // If already connected, then just return OK.
93 if (completed_handshake_) 95 if (completed_handshake_)
94 return OK; 96 return OK;
95 97
96 next_state_ = STATE_RESOLVE_HOST; 98 next_state_ = STATE_RESOLVE_HOST;
99 load_log_ = load_log;
100
101 LoadLog::BeginEvent(load_log, LoadLog::TYPE_SOCKS_CONNECT);
97 102
98 int rv = DoLoop(OK); 103 int rv = DoLoop(OK);
99 if (rv == ERR_IO_PENDING) 104 if (rv == ERR_IO_PENDING) {
100 user_callback_ = callback; 105 user_callback_ = callback;
106 } else {
107 LoadLog::EndEvent(load_log, LoadLog::TYPE_SOCKS_CONNECT);
108 load_log_ = NULL;
109 }
101 return rv; 110 return rv;
102 } 111 }
103 112
104 void SOCKSClientSocket::Disconnect() { 113 void SOCKSClientSocket::Disconnect() {
105 completed_handshake_ = false; 114 completed_handshake_ = false;
106 transport_->Disconnect(); 115 transport_->Disconnect();
107 } 116 }
108 117
109 bool SOCKSClientSocket::IsConnected() const { 118 bool SOCKSClientSocket::IsConnected() const {
110 return completed_handshake_ && transport_->IsConnected(); 119 return completed_handshake_ && transport_->IsConnected();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // clear user_callback_ up front. 161 // clear user_callback_ up front.
153 CompletionCallback* c = user_callback_; 162 CompletionCallback* c = user_callback_;
154 user_callback_ = NULL; 163 user_callback_ = NULL;
155 DLOG(INFO) << "Finished setting up SOCKS handshake"; 164 DLOG(INFO) << "Finished setting up SOCKS handshake";
156 c->Run(result); 165 c->Run(result);
157 } 166 }
158 167
159 void SOCKSClientSocket::OnIOComplete(int result) { 168 void SOCKSClientSocket::OnIOComplete(int result) {
160 DCHECK_NE(STATE_NONE, next_state_); 169 DCHECK_NE(STATE_NONE, next_state_);
161 int rv = DoLoop(result); 170 int rv = DoLoop(result);
162 if (rv != ERR_IO_PENDING) 171 if (rv != ERR_IO_PENDING) {
172 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKS_CONNECT);
173 load_log_ = NULL;
163 DoCallback(rv); 174 DoCallback(rv);
175 }
164 } 176 }
165 177
166 int SOCKSClientSocket::DoLoop(int last_io_result) { 178 int SOCKSClientSocket::DoLoop(int last_io_result) {
167 DCHECK_NE(next_state_, STATE_NONE); 179 DCHECK_NE(next_state_, STATE_NONE);
168 int rv = last_io_result; 180 int rv = last_io_result;
169 do { 181 do {
170 State state = next_state_; 182 State state = next_state_;
171 next_state_ = STATE_NONE; 183 next_state_ = STATE_NONE;
172 switch (state) { 184 switch (state) {
173 case STATE_RESOLVE_HOST: 185 case STATE_RESOLVE_HOST:
(...skipping 24 matching lines...) Expand all
198 } 210 }
199 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 211 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
200 return rv; 212 return rv;
201 } 213 }
202 214
203 int SOCKSClientSocket::DoResolveHost() { 215 int SOCKSClientSocket::DoResolveHost() {
204 DCHECK_EQ(kSOCKS4Unresolved, socks_version_); 216 DCHECK_EQ(kSOCKS4Unresolved, socks_version_);
205 217
206 next_state_ = STATE_RESOLVE_HOST_COMPLETE; 218 next_state_ = STATE_RESOLVE_HOST_COMPLETE;
207 return host_resolver_.Resolve( 219 return host_resolver_.Resolve(
208 host_request_info_, &addresses_, &io_callback_, NULL); 220 host_request_info_, &addresses_, &io_callback_, load_log_);
209 } 221 }
210 222
211 int SOCKSClientSocket::DoResolveHostComplete(int result) { 223 int SOCKSClientSocket::DoResolveHostComplete(int result) {
212 DCHECK_EQ(kSOCKS4Unresolved, socks_version_); 224 DCHECK_EQ(kSOCKS4Unresolved, socks_version_);
213 225
214 bool ok = (result == OK); 226 bool ok = (result == OK);
215 next_state_ = STATE_HANDSHAKE_WRITE; 227 next_state_ = STATE_HANDSHAKE_WRITE;
216 if (ok) { 228 if (ok) {
217 DCHECK(addresses_.head()); 229 DCHECK(addresses_.head());
218 230
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 396 }
385 397
386 #if defined(OS_LINUX) 398 #if defined(OS_LINUX)
387 int SOCKSClientSocket::GetPeerName(struct sockaddr* name, 399 int SOCKSClientSocket::GetPeerName(struct sockaddr* name,
388 socklen_t* namelen) { 400 socklen_t* namelen) {
389 return transport_->GetPeerName(name, namelen); 401 return transport_->GetPeerName(name, namelen);
390 } 402 }
391 #endif 403 #endif
392 404
393 } // namespace net 405 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socks_client_socket.h ('k') | net/socket/socks_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698