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

Side by Side Diff: tools/android/common/adb_connection.cc

Issue 684133002: [Android] Fix gn build for instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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 "tools/android/common/adb_connection.h" 5 #include "tools/android/common/adb_connection.h"
6 6
7 #include <arpa/inet.h> 7 #include <arpa/inet.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 int ConnectAdbHostSocket(const char* forward_to) { 32 int ConnectAdbHostSocket(const char* forward_to) {
33 // ADB port forward request format: HHHHtcp:port:address. 33 // ADB port forward request format: HHHHtcp:port:address.
34 // HHHH is the hexidecimal length of the "tcp:port:address" part. 34 // HHHH is the hexidecimal length of the "tcp:port:address" part.
35 const size_t kBufferMaxLength = 30; 35 const size_t kBufferMaxLength = 30;
36 const size_t kLengthOfLength = 4; 36 const size_t kLengthOfLength = 4;
37 const size_t kAddressMaxLength = kBufferMaxLength - kLengthOfLength;
38 37
39 const char kAddressPrefix[] = { 't', 'c', 'p', ':' }; 38 const char kAddressPrefix[] = { 't', 'c', 'p', ':' };
40 size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to); 39 size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to);
41 if (address_length > kBufferMaxLength - kLengthOfLength) { 40 if (address_length > kBufferMaxLength - kLengthOfLength) {
42 LOG(ERROR) << "Forward to address is too long: " << forward_to; 41 LOG(ERROR) << "Forward to address is too long: " << forward_to;
43 return -1; 42 return -1;
44 } 43 }
45 44
46 char request[kBufferMaxLength]; 45 char request[kBufferMaxLength];
47 memcpy(request + kLengthOfLength, kAddressPrefix, arraysize(kAddressPrefix)); 46 memcpy(request + kLengthOfLength, kAddressPrefix, arraysize(kAddressPrefix));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 if (ret < 0) { 81 if (ret < 0) {
83 LOG(ERROR) << "Failed to send request: " << strerror(errno); 82 LOG(ERROR) << "Failed to send request: " << strerror(errno);
84 CloseSocket(host_socket); 83 CloseSocket(host_socket);
85 return -1; 84 return -1;
86 } 85 }
87 86
88 bytes_sent += ret; 87 bytes_sent += ret;
89 bytes_remaining -= ret; 88 bytes_remaining -= ret;
90 } 89 }
91 90
92 const size_t kAdbStatusLength = 4; 91 const int kAdbStatusLength = 4;
93 char response[kBufferMaxLength]; 92 char response[kBufferMaxLength];
94 int response_length = HANDLE_EINTR(recv(host_socket, response, 93 int response_length = HANDLE_EINTR(recv(host_socket, response,
95 kBufferMaxLength, 0)); 94 kBufferMaxLength, 0));
96 if (response_length < kAdbStatusLength || 95 if (response_length < kAdbStatusLength ||
97 strncmp("OKAY", response, kAdbStatusLength) != 0) { 96 strncmp("OKAY", response, kAdbStatusLength) != 0) {
98 LOG(ERROR) << "Bad response from ADB: length: " << response_length 97 LOG(ERROR) << "Bad response from ADB: length: " << response_length
99 << " data: " << DumpBinary(response, response_length); 98 << " data: " << DumpBinary(response, response_length);
100 CloseSocket(host_socket); 99 CloseSocket(host_socket);
101 return -1; 100 return -1;
102 } 101 }
103 102
104 return host_socket; 103 return host_socket;
105 } 104 }
106 105
107 } // namespace tools 106 } // namespace tools
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698