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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 buffer_ = BuildHandshakeWriteBuffer(); | 336 buffer_ = BuildHandshakeWriteBuffer(); |
337 bytes_sent_ = 0; | 337 bytes_sent_ = 0; |
338 } | 338 } |
339 | 339 |
340 int handshake_buf_len = buffer_.size() - bytes_sent_; | 340 int handshake_buf_len = buffer_.size() - bytes_sent_; |
341 DCHECK_GT(handshake_buf_len, 0); | 341 DCHECK_GT(handshake_buf_len, 0); |
342 handshake_buf_ = new IOBuffer(handshake_buf_len); | 342 handshake_buf_ = new IOBuffer(handshake_buf_len); |
343 memcpy(handshake_buf_->data(), &buffer_[bytes_sent_], | 343 memcpy(handshake_buf_->data(), &buffer_[bytes_sent_], |
344 handshake_buf_len); | 344 handshake_buf_len); |
345 return transport_->socket()->Write( | 345 return transport_->socket()->Write( |
346 handshake_buf_, handshake_buf_len, | 346 handshake_buf_.get(), |
| 347 handshake_buf_len, |
347 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this))); | 348 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this))); |
348 } | 349 } |
349 | 350 |
350 int SOCKSClientSocket::DoHandshakeWriteComplete(int result) { | 351 int SOCKSClientSocket::DoHandshakeWriteComplete(int result) { |
351 if (result < 0) | 352 if (result < 0) |
352 return result; | 353 return result; |
353 | 354 |
354 // We ignore the case when result is 0, since the underlying Write | 355 // We ignore the case when result is 0, since the underlying Write |
355 // may return spurious writes while waiting on the socket. | 356 // may return spurious writes while waiting on the socket. |
356 | 357 |
(...skipping 12 matching lines...) Expand all Loading... |
369 | 370 |
370 int SOCKSClientSocket::DoHandshakeRead() { | 371 int SOCKSClientSocket::DoHandshakeRead() { |
371 next_state_ = STATE_HANDSHAKE_READ_COMPLETE; | 372 next_state_ = STATE_HANDSHAKE_READ_COMPLETE; |
372 | 373 |
373 if (buffer_.empty()) { | 374 if (buffer_.empty()) { |
374 bytes_received_ = 0; | 375 bytes_received_ = 0; |
375 } | 376 } |
376 | 377 |
377 int handshake_buf_len = kReadHeaderSize - bytes_received_; | 378 int handshake_buf_len = kReadHeaderSize - bytes_received_; |
378 handshake_buf_ = new IOBuffer(handshake_buf_len); | 379 handshake_buf_ = new IOBuffer(handshake_buf_len); |
379 return transport_->socket()->Read(handshake_buf_, handshake_buf_len, | 380 return transport_->socket()->Read( |
380 base::Bind(&SOCKSClientSocket::OnIOComplete, | 381 handshake_buf_.get(), |
381 base::Unretained(this))); | 382 handshake_buf_len, |
| 383 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this))); |
382 } | 384 } |
383 | 385 |
384 int SOCKSClientSocket::DoHandshakeReadComplete(int result) { | 386 int SOCKSClientSocket::DoHandshakeReadComplete(int result) { |
385 if (result < 0) | 387 if (result < 0) |
386 return result; | 388 return result; |
387 | 389 |
388 // The underlying socket closed unexpectedly. | 390 // The underlying socket closed unexpectedly. |
389 if (result == 0) | 391 if (result == 0) |
390 return ERR_CONNECTION_CLOSED; | 392 return ERR_CONNECTION_CLOSED; |
391 | 393 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 436 |
435 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const { | 437 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const { |
436 return transport_->socket()->GetPeerAddress(address); | 438 return transport_->socket()->GetPeerAddress(address); |
437 } | 439 } |
438 | 440 |
439 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { | 441 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { |
440 return transport_->socket()->GetLocalAddress(address); | 442 return transport_->socket()->GetLocalAddress(address); |
441 } | 443 } |
442 | 444 |
443 } // namespace net | 445 } // namespace net |
OLD | NEW |