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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 new HttpOverAdbSocket(port, serial, socket_name, request_path, | 358 new HttpOverAdbSocket(port, serial, socket_name, request_path, |
359 callback); | 359 callback); |
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 // In a IPv4/IPv6 dual stack environment, getaddrinfo for localhost could |
369 net::IPAddress::IPv4Localhost(), port_); | 369 // only return IPv6 address while current adb (1.0.36) will always listen |
| 370 // on IPv4. So just try IPv4 first, then fall back to IPv6. |
| 371 net::IPAddressList list = {net::IPAddress::IPv4Localhost(), |
| 372 net::IPAddress::IPv6Localhost()}; |
| 373 net::AddressList ip_list = net::AddressList::CreateFromIPAddressList( |
| 374 list, "localhost"); |
| 375 net::AddressList address_list = net::AddressList::CopyWithPort( |
| 376 ip_list, port_); |
| 377 |
370 socket_.reset(new net::TCPClientSocket(address_list, NULL, NULL, | 378 socket_.reset(new net::TCPClientSocket(address_list, NULL, NULL, |
371 net::NetLog::Source())); | 379 net::NetLog::Source())); |
372 int result = socket_->Connect(callback); | 380 int result = socket_->Connect(callback); |
373 if (result != net::ERR_IO_PENDING) | 381 if (result != net::ERR_IO_PENDING) |
374 callback.Run(result); | 382 callback.Run(result); |
375 } | 383 } |
376 | 384 |
377 void AdbClientSocket::SendCommand(const std::string& command, | 385 void AdbClientSocket::SendCommand(const std::string& command, |
378 bool is_void, | 386 bool is_void, |
379 bool has_length, | 387 bool has_length, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 base::Unretained(this), | 534 base::Unretained(this), |
527 callback, | 535 callback, |
528 new_response, | 536 new_response, |
529 response_buffer, | 537 response_buffer, |
530 bytes_left)); | 538 bytes_left)); |
531 if (result > 0) | 539 if (result > 0) |
532 OnResponseData(callback, new_response, response_buffer, bytes_left, result); | 540 OnResponseData(callback, new_response, response_buffer, bytes_left, result); |
533 else if (result != net::ERR_IO_PENDING) | 541 else if (result != net::ERR_IO_PENDING) |
534 callback.Run(net::OK, new_response); | 542 callback.Run(net::OK, new_response); |
535 } | 543 } |
OLD | NEW |