Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/net/adb_client_socket.h" | 5 #include "chrome/test/chromedriver/net/adb_client_socket.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } | 360 } |
| 361 | 361 |
| 362 AdbClientSocket::AdbClientSocket(int port) : port_(port) {} | 362 AdbClientSocket::AdbClientSocket(int port) : port_(port) {} |
| 363 | 363 |
| 364 AdbClientSocket::~AdbClientSocket() { | 364 AdbClientSocket::~AdbClientSocket() { |
| 365 } | 365 } |
| 366 | 366 |
| 367 void AdbClientSocket::Connect(const net::CompletionCallback& callback) { | 367 void AdbClientSocket::Connect(const net::CompletionCallback& callback) { |
| 368 net::AddressList address_list = net::AddressList::CreateFromIPAddress( | 368 net::AddressList address_list = net::AddressList::CreateFromIPAddress( |
| 369 net::IPAddress::IPv4Localhost(), port_); | 369 net::IPAddress::IPv4Localhost(), port_); |
| 370 socket_.reset(new net::TCPClientSocket(address_list, NULL, NULL, | 370 socket_.reset(new net::TCPClientSocket(address_list, NULL, NULL, |
|
pmarks
2016/09/20 00:42:13
It looks like TCPClientSocket already supports con
lepton
2016/09/20 08:04:11
Done.
| |
| 371 net::NetLog::Source())); | 371 net::NetLog::Source())); |
| 372 int result = socket_->Connect(callback); | 372 int result = socket_->Connect(callback); |
| 373 if (result == net::ERR_ADDRESS_UNREACHABLE) { | |
| 374 VLOG(0) << "connect to IPv4 failed, trying IPv6"; | |
| 375 address_list = | |
| 376 net::AddressList::CreateFromIPAddress(net::IPAddress::IPv6Localhost(), | |
| 377 port_); | |
| 378 socket_.reset(new net::TCPClientSocket(address_list, NULL, NULL, | |
| 379 net::NetLog::Source())); | |
| 380 result = socket_->Connect(callback); | |
| 381 } | |
| 373 if (result != net::ERR_IO_PENDING) | 382 if (result != net::ERR_IO_PENDING) |
| 374 callback.Run(result); | 383 callback.Run(result); |
| 375 } | 384 } |
| 376 | 385 |
| 377 void AdbClientSocket::SendCommand(const std::string& command, | 386 void AdbClientSocket::SendCommand(const std::string& command, |
| 378 bool is_void, | 387 bool is_void, |
| 379 bool has_length, | 388 bool has_length, |
| 380 const CommandCallback& callback) { | 389 const CommandCallback& callback) { |
| 381 scoped_refptr<net::StringIOBuffer> request_buffer = | 390 scoped_refptr<net::StringIOBuffer> request_buffer = |
| 382 new net::StringIOBuffer(EncodeMessage(command)); | 391 new net::StringIOBuffer(EncodeMessage(command)); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 base::Unretained(this), | 535 base::Unretained(this), |
| 527 callback, | 536 callback, |
| 528 new_response, | 537 new_response, |
| 529 response_buffer, | 538 response_buffer, |
| 530 bytes_left)); | 539 bytes_left)); |
| 531 if (result > 0) | 540 if (result > 0) |
| 532 OnResponseData(callback, new_response, response_buffer, bytes_left, result); | 541 OnResponseData(callback, new_response, response_buffer, bytes_left, result); |
| 533 else if (result != net::ERR_IO_PENDING) | 542 else if (result != net::ERR_IO_PENDING) |
| 534 callback.Run(net::OK, new_response); | 543 callback.Run(net::OK, new_response); |
| 535 } | 544 } |
| OLD | NEW |