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

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

Issue 1696005: Add net log entries that summarize transmit and receive byte counts. (Closed)
Patch Set: More tests and address comments Created 10 years, 8 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.h ('k') | net/socket/socks5_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) 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/socks5_client_socket.h" 5 #include "net/socket/socks5_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/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/trace_event.h" 11 #include "base/trace_event.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const HostResolver::RequestInfo& req_info) 52 const HostResolver::RequestInfo& req_info)
53 : ALLOW_THIS_IN_INITIALIZER_LIST( 53 : ALLOW_THIS_IN_INITIALIZER_LIST(
54 io_callback_(this, &SOCKS5ClientSocket::OnIOComplete)), 54 io_callback_(this, &SOCKS5ClientSocket::OnIOComplete)),
55 transport_(transport_socket), 55 transport_(transport_socket),
56 next_state_(STATE_NONE), 56 next_state_(STATE_NONE),
57 user_callback_(NULL), 57 user_callback_(NULL),
58 completed_handshake_(false), 58 completed_handshake_(false),
59 bytes_sent_(0), 59 bytes_sent_(0),
60 bytes_received_(0), 60 bytes_received_(0),
61 read_header_size(kReadHeaderSize), 61 read_header_size(kReadHeaderSize),
62 host_request_info_(req_info) { 62 host_request_info_(req_info),
63 net_log_(transport_socket->socket()->NetLog()) {
63 } 64 }
64 65
65 SOCKS5ClientSocket::SOCKS5ClientSocket( 66 SOCKS5ClientSocket::SOCKS5ClientSocket(
66 ClientSocket* transport_socket, 67 ClientSocket* transport_socket,
67 const HostResolver::RequestInfo& req_info) 68 const HostResolver::RequestInfo& req_info)
68 : ALLOW_THIS_IN_INITIALIZER_LIST( 69 : ALLOW_THIS_IN_INITIALIZER_LIST(
69 io_callback_(this, &SOCKS5ClientSocket::OnIOComplete)), 70 io_callback_(this, &SOCKS5ClientSocket::OnIOComplete)),
70 transport_(new ClientSocketHandle()), 71 transport_(new ClientSocketHandle()),
71 next_state_(STATE_NONE), 72 next_state_(STATE_NONE),
72 user_callback_(NULL), 73 user_callback_(NULL),
73 completed_handshake_(false), 74 completed_handshake_(false),
74 bytes_sent_(0), 75 bytes_sent_(0),
75 bytes_received_(0), 76 bytes_received_(0),
76 read_header_size(kReadHeaderSize), 77 read_header_size(kReadHeaderSize),
77 host_request_info_(req_info) { 78 host_request_info_(req_info),
79 net_log_(transport_socket->NetLog()) {
78 transport_->set_socket(transport_socket); 80 transport_->set_socket(transport_socket);
79 } 81 }
80 82
81 SOCKS5ClientSocket::~SOCKS5ClientSocket() { 83 SOCKS5ClientSocket::~SOCKS5ClientSocket() {
82 Disconnect(); 84 Disconnect();
83 } 85 }
84 86
85 int SOCKS5ClientSocket::Connect(CompletionCallback* callback, 87 int SOCKS5ClientSocket::Connect(CompletionCallback* callback) {
86 const BoundNetLog& net_log) {
87 DCHECK(transport_.get()); 88 DCHECK(transport_.get());
88 DCHECK(transport_->socket()); 89 DCHECK(transport_->socket());
89 DCHECK(transport_->socket()->IsConnected()); 90 DCHECK(transport_->socket()->IsConnected());
90 DCHECK_EQ(STATE_NONE, next_state_); 91 DCHECK_EQ(STATE_NONE, next_state_);
91 DCHECK(!user_callback_); 92 DCHECK(!user_callback_);
92 93
93 // If already connected, then just return OK. 94 // If already connected, then just return OK.
94 if (completed_handshake_) 95 if (completed_handshake_)
95 return OK; 96 return OK;
96 97
97 net_log_ = net_log; 98 net_log_.BeginEvent(NetLog::TYPE_SOCKS5_CONNECT);
98 net_log.BeginEvent(NetLog::TYPE_SOCKS5_CONNECT);
99 99
100 next_state_ = STATE_GREET_WRITE; 100 next_state_ = STATE_GREET_WRITE;
101 buffer_.clear(); 101 buffer_.clear();
102 102
103 int rv = DoLoop(OK); 103 int rv = DoLoop(OK);
104 if (rv == ERR_IO_PENDING) { 104 if (rv == ERR_IO_PENDING) {
105 user_callback_ = callback; 105 user_callback_ = callback;
106 } else { 106 } else {
107 net_log.EndEvent(NetLog::TYPE_SOCKS5_CONNECT); 107 net_log_.EndEvent(NetLog::TYPE_SOCKS5_CONNECT);
108 net_log_ = BoundNetLog();
109 } 108 }
110 return rv; 109 return rv;
111 } 110 }
112 111
113 void SOCKS5ClientSocket::Disconnect() { 112 void SOCKS5ClientSocket::Disconnect() {
114 completed_handshake_ = false; 113 completed_handshake_ = false;
115 transport_->socket()->Disconnect(); 114 transport_->socket()->Disconnect();
116 115
117 // Reset other states to make sure they aren't mistakenly used later. 116 // Reset other states to make sure they aren't mistakenly used later.
118 // These are the states initialized by Connect(). 117 // These are the states initialized by Connect().
119 next_state_ = STATE_NONE; 118 next_state_ = STATE_NONE;
120 user_callback_ = NULL; 119 user_callback_ = NULL;
121 net_log_ = BoundNetLog();
122 } 120 }
123 121
124 bool SOCKS5ClientSocket::IsConnected() const { 122 bool SOCKS5ClientSocket::IsConnected() const {
125 return completed_handshake_ && transport_->socket()->IsConnected(); 123 return completed_handshake_ && transport_->socket()->IsConnected();
126 } 124 }
127 125
128 bool SOCKS5ClientSocket::IsConnectedAndIdle() const { 126 bool SOCKS5ClientSocket::IsConnectedAndIdle() const {
129 return completed_handshake_ && transport_->socket()->IsConnectedAndIdle(); 127 return completed_handshake_ && transport_->socket()->IsConnectedAndIdle();
130 } 128 }
131 129
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 CompletionCallback* c = user_callback_; 166 CompletionCallback* c = user_callback_;
169 user_callback_ = NULL; 167 user_callback_ = NULL;
170 c->Run(result); 168 c->Run(result);
171 } 169 }
172 170
173 void SOCKS5ClientSocket::OnIOComplete(int result) { 171 void SOCKS5ClientSocket::OnIOComplete(int result) {
174 DCHECK_NE(STATE_NONE, next_state_); 172 DCHECK_NE(STATE_NONE, next_state_);
175 int rv = DoLoop(result); 173 int rv = DoLoop(result);
176 if (rv != ERR_IO_PENDING) { 174 if (rv != ERR_IO_PENDING) {
177 net_log_.EndEvent(NetLog::TYPE_SOCKS5_CONNECT); 175 net_log_.EndEvent(NetLog::TYPE_SOCKS5_CONNECT);
178 net_log_ = BoundNetLog();
179 DoCallback(rv); 176 DoCallback(rv);
180 } 177 }
181 } 178 }
182 179
183 int SOCKS5ClientSocket::DoLoop(int last_io_result) { 180 int SOCKS5ClientSocket::DoLoop(int last_io_result) {
184 DCHECK_NE(next_state_, STATE_NONE); 181 DCHECK_NE(next_state_, STATE_NONE);
185 int rv = last_io_result; 182 int rv = last_io_result;
186 do { 183 do {
187 State state = next_state_; 184 State state = next_state_;
188 next_state_ = STATE_NONE; 185 next_state_ = STATE_NONE;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 465
469 next_state_ = STATE_HANDSHAKE_READ; 466 next_state_ = STATE_HANDSHAKE_READ;
470 return OK; 467 return OK;
471 } 468 }
472 469
473 int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const { 470 int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const {
474 return transport_->socket()->GetPeerAddress(address); 471 return transport_->socket()->GetPeerAddress(address);
475 } 472 }
476 473
477 } // namespace net 474 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socks5_client_socket.h ('k') | net/socket/socks5_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698