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

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

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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/socks5_client_socket_unittest.cc ('k') | net/socket/socks_client_socket_pool.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) 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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/sys_byteorder.h" 12 #include "base/sys_byteorder.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/log/net_log.h" 14 #include "net/log/net_log.h"
15 #include "net/log/net_log_event_type.h"
15 #include "net/socket/client_socket_handle.h" 16 #include "net/socket/client_socket_handle.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 // Every SOCKS server requests a user-id from the client. It is optional 20 // Every SOCKS server requests a user-id from the client. It is optional
20 // and we send an empty string. 21 // and we send an empty string.
21 static const char kEmptyUserId[] = ""; 22 static const char kEmptyUserId[] = "";
22 23
23 // For SOCKS4, the client sends 8 bytes plus the size of the user-id. 24 // For SOCKS4, the client sends 8 bytes plus the size of the user-id.
24 static const unsigned int kWriteHeaderSize = 8; 25 static const unsigned int kWriteHeaderSize = 8;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 DCHECK(transport_->socket()); 82 DCHECK(transport_->socket());
82 DCHECK_EQ(STATE_NONE, next_state_); 83 DCHECK_EQ(STATE_NONE, next_state_);
83 DCHECK(user_callback_.is_null()); 84 DCHECK(user_callback_.is_null());
84 85
85 // If already connected, then just return OK. 86 // If already connected, then just return OK.
86 if (completed_handshake_) 87 if (completed_handshake_)
87 return OK; 88 return OK;
88 89
89 next_state_ = STATE_RESOLVE_HOST; 90 next_state_ = STATE_RESOLVE_HOST;
90 91
91 net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT); 92 net_log_.BeginEvent(NetLogEventType::SOCKS_CONNECT);
92 93
93 int rv = DoLoop(OK); 94 int rv = DoLoop(OK);
94 if (rv == ERR_IO_PENDING) { 95 if (rv == ERR_IO_PENDING) {
95 user_callback_ = callback; 96 user_callback_ = callback;
96 } else { 97 } else {
97 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv); 98 net_log_.EndEventWithNetErrorCode(NetLogEventType::SOCKS_CONNECT, rv);
98 } 99 }
99 return rv; 100 return rv;
100 } 101 }
101 102
102 void SOCKSClientSocket::Disconnect() { 103 void SOCKSClientSocket::Disconnect() {
103 completed_handshake_ = false; 104 completed_handshake_ = false;
104 request_.reset(); 105 request_.reset();
105 transport_->socket()->Disconnect(); 106 transport_->socket()->Disconnect();
106 107
107 // Reset other states to make sure they aren't mistakenly used later. 108 // Reset other states to make sure they aren't mistakenly used later.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // Since Run() may result in Read being called, 226 // Since Run() may result in Read being called,
226 // clear user_callback_ up front. 227 // clear user_callback_ up front.
227 DVLOG(1) << "Finished setting up SOCKS handshake"; 228 DVLOG(1) << "Finished setting up SOCKS handshake";
228 base::ResetAndReturn(&user_callback_).Run(result); 229 base::ResetAndReturn(&user_callback_).Run(result);
229 } 230 }
230 231
231 void SOCKSClientSocket::OnIOComplete(int result) { 232 void SOCKSClientSocket::OnIOComplete(int result) {
232 DCHECK_NE(STATE_NONE, next_state_); 233 DCHECK_NE(STATE_NONE, next_state_);
233 int rv = DoLoop(result); 234 int rv = DoLoop(result);
234 if (rv != ERR_IO_PENDING) { 235 if (rv != ERR_IO_PENDING) {
235 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv); 236 net_log_.EndEventWithNetErrorCode(NetLogEventType::SOCKS_CONNECT, rv);
236 DoCallback(rv); 237 DoCallback(rv);
237 } 238 }
238 } 239 }
239 240
240 void SOCKSClientSocket::OnReadWriteComplete(const CompletionCallback& callback, 241 void SOCKSClientSocket::OnReadWriteComplete(const CompletionCallback& callback,
241 int result) { 242 int result) {
242 DCHECK_NE(ERR_IO_PENDING, result); 243 DCHECK_NE(ERR_IO_PENDING, result);
243 DCHECK(!callback.is_null()); 244 DCHECK(!callback.is_null());
244 245
245 if (result > 0) 246 if (result > 0)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 445
445 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const { 446 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const {
446 return transport_->socket()->GetPeerAddress(address); 447 return transport_->socket()->GetPeerAddress(address);
447 } 448 }
448 449
449 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { 450 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const {
450 return transport_->socket()->GetLocalAddress(address); 451 return transport_->socket()->GetLocalAddress(address);
451 } 452 }
452 453
453 } // namespace net 454 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socks5_client_socket_unittest.cc ('k') | net/socket/socks_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698