OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/trace_event.h" | 9 #include "base/trace_event.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 DCHECK(transport_->socket()->IsConnected()); | 105 DCHECK(transport_->socket()->IsConnected()); |
106 DCHECK_EQ(STATE_NONE, next_state_); | 106 DCHECK_EQ(STATE_NONE, next_state_); |
107 DCHECK(!user_callback_); | 107 DCHECK(!user_callback_); |
108 | 108 |
109 // If already connected, then just return OK. | 109 // If already connected, then just return OK. |
110 if (completed_handshake_) | 110 if (completed_handshake_) |
111 return OK; | 111 return OK; |
112 | 112 |
113 next_state_ = STATE_RESOLVE_HOST; | 113 next_state_ = STATE_RESOLVE_HOST; |
114 | 114 |
115 net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT); | 115 net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT, NULL); |
116 | 116 |
117 int rv = DoLoop(OK); | 117 int rv = DoLoop(OK); |
118 if (rv == ERR_IO_PENDING) { | 118 if (rv == ERR_IO_PENDING) { |
119 user_callback_ = callback; | 119 user_callback_ = callback; |
120 } else { | 120 } else { |
121 net_log_.EndEvent(NetLog::TYPE_SOCKS_CONNECT); | 121 net_log_.EndEvent(NetLog::TYPE_SOCKS_CONNECT, NULL); |
122 } | 122 } |
123 return rv; | 123 return rv; |
124 } | 124 } |
125 | 125 |
126 void SOCKSClientSocket::Disconnect() { | 126 void SOCKSClientSocket::Disconnect() { |
127 completed_handshake_ = false; | 127 completed_handshake_ = false; |
128 host_resolver_.Cancel(); | 128 host_resolver_.Cancel(); |
129 transport_->socket()->Disconnect(); | 129 transport_->socket()->Disconnect(); |
130 | 130 |
131 // Reset other states to make sure they aren't mistakenly used later. | 131 // Reset other states to make sure they aren't mistakenly used later. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 CompletionCallback* c = user_callback_; | 181 CompletionCallback* c = user_callback_; |
182 user_callback_ = NULL; | 182 user_callback_ = NULL; |
183 DLOG(INFO) << "Finished setting up SOCKS handshake"; | 183 DLOG(INFO) << "Finished setting up SOCKS handshake"; |
184 c->Run(result); | 184 c->Run(result); |
185 } | 185 } |
186 | 186 |
187 void SOCKSClientSocket::OnIOComplete(int result) { | 187 void SOCKSClientSocket::OnIOComplete(int result) { |
188 DCHECK_NE(STATE_NONE, next_state_); | 188 DCHECK_NE(STATE_NONE, next_state_); |
189 int rv = DoLoop(result); | 189 int rv = DoLoop(result); |
190 if (rv != ERR_IO_PENDING) { | 190 if (rv != ERR_IO_PENDING) { |
191 net_log_.EndEvent(NetLog::TYPE_SOCKS_CONNECT); | 191 net_log_.EndEvent(NetLog::TYPE_SOCKS_CONNECT, NULL); |
192 DoCallback(rv); | 192 DoCallback(rv); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 int SOCKSClientSocket::DoLoop(int last_io_result) { | 196 int SOCKSClientSocket::DoLoop(int last_io_result) { |
197 DCHECK_NE(next_state_, STATE_NONE); | 197 DCHECK_NE(next_state_, STATE_NONE); |
198 int rv = last_io_result; | 198 int rv = last_io_result; |
199 do { | 199 do { |
200 State state = next_state_; | 200 State state = next_state_; |
201 next_state_ = STATE_NONE; | 201 next_state_ = STATE_NONE; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 | 415 |
416 // Note: we ignore the last 6 bytes as specified by the SOCKS protocol | 416 // Note: we ignore the last 6 bytes as specified by the SOCKS protocol |
417 } | 417 } |
418 | 418 |
419 int SOCKSClientSocket::GetPeerAddress(AddressList* address) const { | 419 int SOCKSClientSocket::GetPeerAddress(AddressList* address) const { |
420 return transport_->socket()->GetPeerAddress(address); | 420 return transport_->socket()->GetPeerAddress(address); |
421 } | 421 } |
422 | 422 |
423 } // namespace net | 423 } // namespace net |
OLD | NEW |