| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (rv == ERR_IO_PENDING) { | 94 if (rv == ERR_IO_PENDING) { |
| 95 user_callback_ = callback; | 95 user_callback_ = callback; |
| 96 } else { | 96 } else { |
| 97 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv); | 97 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv); |
| 98 } | 98 } |
| 99 return rv; | 99 return rv; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void SOCKSClientSocket::Disconnect() { | 102 void SOCKSClientSocket::Disconnect() { |
| 103 completed_handshake_ = false; | 103 completed_handshake_ = false; |
| 104 host_resolver_.Cancel(); | 104 request_.reset(); |
| 105 transport_->socket()->Disconnect(); | 105 transport_->socket()->Disconnect(); |
| 106 | 106 |
| 107 // Reset other states to make sure they aren't mistakenly used later. | 107 // Reset other states to make sure they aren't mistakenly used later. |
| 108 // These are the states initialized by Connect(). | 108 // These are the states initialized by Connect(). |
| 109 next_state_ = STATE_NONE; | 109 next_state_ = STATE_NONE; |
| 110 user_callback_.Reset(); | 110 user_callback_.Reset(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool SOCKSClientSocket::IsConnected() const { | 113 bool SOCKSClientSocket::IsConnected() const { |
| 114 return completed_handshake_ && transport_->socket()->IsConnected(); | 114 return completed_handshake_ && transport_->socket()->IsConnected(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 282 } |
| 283 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 283 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 284 return rv; | 284 return rv; |
| 285 } | 285 } |
| 286 | 286 |
| 287 int SOCKSClientSocket::DoResolveHost() { | 287 int SOCKSClientSocket::DoResolveHost() { |
| 288 next_state_ = STATE_RESOLVE_HOST_COMPLETE; | 288 next_state_ = STATE_RESOLVE_HOST_COMPLETE; |
| 289 // SOCKS4 only supports IPv4 addresses, so only try getting the IPv4 | 289 // SOCKS4 only supports IPv4 addresses, so only try getting the IPv4 |
| 290 // addresses for the target host. | 290 // addresses for the target host. |
| 291 host_request_info_.set_address_family(ADDRESS_FAMILY_IPV4); | 291 host_request_info_.set_address_family(ADDRESS_FAMILY_IPV4); |
| 292 return host_resolver_.Resolve( | 292 return host_resolver_->Resolve( |
| 293 host_request_info_, | 293 host_request_info_, priority_, &addresses_, |
| 294 priority_, | |
| 295 &addresses_, | |
| 296 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)), | 294 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)), |
| 297 net_log_); | 295 &request_, net_log_); |
| 298 } | 296 } |
| 299 | 297 |
| 300 int SOCKSClientSocket::DoResolveHostComplete(int result) { | 298 int SOCKSClientSocket::DoResolveHostComplete(int result) { |
| 301 if (result != OK) { | 299 if (result != OK) { |
| 302 // Resolving the hostname failed; fail the request rather than automatically | 300 // Resolving the hostname failed; fail the request rather than automatically |
| 303 // falling back to SOCKS4a (since it can be confusing to see invalid IP | 301 // falling back to SOCKS4a (since it can be confusing to see invalid IP |
| 304 // addresses being sent to the SOCKS4 server when it doesn't support 4A.) | 302 // addresses being sent to the SOCKS4 server when it doesn't support 4A.) |
| 305 return result; | 303 return result; |
| 306 } | 304 } |
| 307 | 305 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 444 |
| 447 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const { | 445 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const { |
| 448 return transport_->socket()->GetPeerAddress(address); | 446 return transport_->socket()->GetPeerAddress(address); |
| 449 } | 447 } |
| 450 | 448 |
| 451 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { | 449 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { |
| 452 return transport_->socket()->GetLocalAddress(address); | 450 return transport_->socket()->GetLocalAddress(address); |
| 453 } | 451 } |
| 454 | 452 |
| 455 } // namespace net | 453 } // namespace net |
| OLD | NEW |