summaryrefslogtreecommitdiff
path: root/adb_client.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-30 17:32:03 -0700
committerElliott Hughes <enh@google.com>2015-05-01 15:55:37 -0700
commit080c004a20ead6229e2bef1a04f30c6cbf44a0c0 (patch)
tree5eae0ad266a6ac7680a12dd088142c1fb953fc7c /adb_client.cpp
parent2f421aacbec93c350d97bd89cc27adc200da5a68 (diff)
downloadadb-080c004a20ead6229e2bef1a04f30c6cbf44a0c0.tar.gz
More adb buffer fixes.
This patch factors out a lot of the basic protocol code: sending OKAY, sending FAIL, and sending a length-prefixed string. ADB_TRACE has been non-optional for a long time, so let's just remove the #ifs. Also actually build the device tracker test tool (and remove its duplicate). Bug: http://b/20666660 Change-Id: I6c7d59f18707bdc62ca69dea45547617f9f31fc6
Diffstat (limited to 'adb_client.cpp')
-rw-r--r--adb_client.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/adb_client.cpp b/adb_client.cpp
index 62f79fa..33eee82 100644
--- a/adb_client.cpp
+++ b/adb_client.cpp
@@ -56,7 +56,7 @@ static bool ReadProtocolString(int fd, std::string* s, std::string* error) {
buf[4] = 0;
unsigned long len = strtoul(buf, 0, 16);
- s->resize(len + 1, '\0'); // Ensure NUL-termination.
+ s->resize(len, '\0');
if (!ReadFdExactly(fd, &(*s)[0], len)) {
*error = perror_str("protocol fault (couldn't read status message)");
return false;
@@ -136,9 +136,7 @@ static int switch_socket_transport(int fd, std::string* error) {
service += transport_type;
}
- char tmp[5];
- snprintf(tmp, sizeof(tmp), "%04zx", service.size());
- if (!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, service.c_str(), service.size())) {
+ if (!SendProtocolString(fd, service)) {
*error = perror_str("write failure during connection");
adb_close(fd);
return -1;
@@ -199,9 +197,7 @@ int _adb_connect(const std::string& service, std::string* error) {
return -1;
}
- char tmp[5];
- snprintf(tmp, sizeof(tmp), "%04zx", service.size());
- if(!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, &service[0], service.size())) {
+ if(!SendProtocolString(fd, service)) {
*error = perror_str("write failure during connection");
adb_close(fd);
return -1;