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

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

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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 | Annotate | Revision Log
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/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/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 buffer_ = std::string(kSOCKS5GreetWriteData, 284 buffer_ = std::string(kSOCKS5GreetWriteData,
285 arraysize(kSOCKS5GreetWriteData)); 285 arraysize(kSOCKS5GreetWriteData));
286 bytes_sent_ = 0; 286 bytes_sent_ = 0;
287 } 287 }
288 288
289 next_state_ = STATE_GREET_WRITE_COMPLETE; 289 next_state_ = STATE_GREET_WRITE_COMPLETE;
290 size_t handshake_buf_len = buffer_.size() - bytes_sent_; 290 size_t handshake_buf_len = buffer_.size() - bytes_sent_;
291 handshake_buf_ = new IOBuffer(handshake_buf_len); 291 handshake_buf_ = new IOBuffer(handshake_buf_len);
292 memcpy(handshake_buf_->data(), &buffer_.data()[bytes_sent_], 292 memcpy(handshake_buf_->data(), &buffer_.data()[bytes_sent_],
293 handshake_buf_len); 293 handshake_buf_len);
294 return transport_->socket()->Write(handshake_buf_, handshake_buf_len, 294 return transport_->socket()
295 io_callback_); 295 ->Write(handshake_buf_.get(), handshake_buf_len, io_callback_);
296 } 296 }
297 297
298 int SOCKS5ClientSocket::DoGreetWriteComplete(int result) { 298 int SOCKS5ClientSocket::DoGreetWriteComplete(int result) {
299 if (result < 0) 299 if (result < 0)
300 return result; 300 return result;
301 301
302 bytes_sent_ += result; 302 bytes_sent_ += result;
303 if (bytes_sent_ == buffer_.size()) { 303 if (bytes_sent_ == buffer_.size()) {
304 buffer_.clear(); 304 buffer_.clear();
305 bytes_received_ = 0; 305 bytes_received_ = 0;
306 next_state_ = STATE_GREET_READ; 306 next_state_ = STATE_GREET_READ;
307 } else { 307 } else {
308 next_state_ = STATE_GREET_WRITE; 308 next_state_ = STATE_GREET_WRITE;
309 } 309 }
310 return OK; 310 return OK;
311 } 311 }
312 312
313 int SOCKS5ClientSocket::DoGreetRead() { 313 int SOCKS5ClientSocket::DoGreetRead() {
314 next_state_ = STATE_GREET_READ_COMPLETE; 314 next_state_ = STATE_GREET_READ_COMPLETE;
315 size_t handshake_buf_len = kGreetReadHeaderSize - bytes_received_; 315 size_t handshake_buf_len = kGreetReadHeaderSize - bytes_received_;
316 handshake_buf_ = new IOBuffer(handshake_buf_len); 316 handshake_buf_ = new IOBuffer(handshake_buf_len);
317 return transport_->socket()->Read(handshake_buf_, handshake_buf_len, 317 return transport_->socket()
318 io_callback_); 318 ->Read(handshake_buf_.get(), handshake_buf_len, io_callback_);
319 } 319 }
320 320
321 int SOCKS5ClientSocket::DoGreetReadComplete(int result) { 321 int SOCKS5ClientSocket::DoGreetReadComplete(int result) {
322 if (result < 0) 322 if (result < 0)
323 return result; 323 return result;
324 324
325 if (result == 0) { 325 if (result == 0) {
326 net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_GREETING); 326 net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_GREETING);
327 return ERR_SOCKS_CONNECTION_FAILED; 327 return ERR_SOCKS_CONNECTION_FAILED;
328 } 328 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (rv != OK) 382 if (rv != OK)
383 return rv; 383 return rv;
384 bytes_sent_ = 0; 384 bytes_sent_ = 0;
385 } 385 }
386 386
387 int handshake_buf_len = buffer_.size() - bytes_sent_; 387 int handshake_buf_len = buffer_.size() - bytes_sent_;
388 DCHECK_LT(0, handshake_buf_len); 388 DCHECK_LT(0, handshake_buf_len);
389 handshake_buf_ = new IOBuffer(handshake_buf_len); 389 handshake_buf_ = new IOBuffer(handshake_buf_len);
390 memcpy(handshake_buf_->data(), &buffer_[bytes_sent_], 390 memcpy(handshake_buf_->data(), &buffer_[bytes_sent_],
391 handshake_buf_len); 391 handshake_buf_len);
392 return transport_->socket()->Write(handshake_buf_, handshake_buf_len, 392 return transport_->socket()
393 io_callback_); 393 ->Write(handshake_buf_.get(), handshake_buf_len, io_callback_);
394 } 394 }
395 395
396 int SOCKS5ClientSocket::DoHandshakeWriteComplete(int result) { 396 int SOCKS5ClientSocket::DoHandshakeWriteComplete(int result) {
397 if (result < 0) 397 if (result < 0)
398 return result; 398 return result;
399 399
400 // We ignore the case when result is 0, since the underlying Write 400 // We ignore the case when result is 0, since the underlying Write
401 // may return spurious writes while waiting on the socket. 401 // may return spurious writes while waiting on the socket.
402 402
403 bytes_sent_ += result; 403 bytes_sent_ += result;
(...skipping 12 matching lines...) Expand all
416 int SOCKS5ClientSocket::DoHandshakeRead() { 416 int SOCKS5ClientSocket::DoHandshakeRead() {
417 next_state_ = STATE_HANDSHAKE_READ_COMPLETE; 417 next_state_ = STATE_HANDSHAKE_READ_COMPLETE;
418 418
419 if (buffer_.empty()) { 419 if (buffer_.empty()) {
420 bytes_received_ = 0; 420 bytes_received_ = 0;
421 read_header_size = kReadHeaderSize; 421 read_header_size = kReadHeaderSize;
422 } 422 }
423 423
424 int handshake_buf_len = read_header_size - bytes_received_; 424 int handshake_buf_len = read_header_size - bytes_received_;
425 handshake_buf_ = new IOBuffer(handshake_buf_len); 425 handshake_buf_ = new IOBuffer(handshake_buf_len);
426 return transport_->socket()->Read(handshake_buf_, handshake_buf_len, 426 return transport_->socket()
427 io_callback_); 427 ->Read(handshake_buf_.get(), handshake_buf_len, io_callback_);
428 } 428 }
429 429
430 int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) { 430 int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
431 if (result < 0) 431 if (result < 0)
432 return result; 432 return result;
433 433
434 // The underlying socket closed unexpectedly. 434 // The underlying socket closed unexpectedly.
435 if (result == 0) { 435 if (result == 0) {
436 net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE); 436 net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE);
437 return ERR_SOCKS_CONNECTION_FAILED; 437 return ERR_SOCKS_CONNECTION_FAILED;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 494
495 int SOCKS5ClientSocket::GetPeerAddress(IPEndPoint* address) const { 495 int SOCKS5ClientSocket::GetPeerAddress(IPEndPoint* address) const {
496 return transport_->socket()->GetPeerAddress(address); 496 return transport_->socket()->GetPeerAddress(address);
497 } 497 }
498 498
499 int SOCKS5ClientSocket::GetLocalAddress(IPEndPoint* address) const { 499 int SOCKS5ClientSocket::GetLocalAddress(IPEndPoint* address) const {
500 return transport_->socket()->GetLocalAddress(address); 500 return transport_->socket()->GetLocalAddress(address);
501 } 501 }
502 502
503 } // namespace net 503 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/deterministic_socket_data_unittest.cc ('k') | net/socket/socks5_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698