adb: Distinguish betwen already-connected and connection failure

This change returns a different value (-EALREADY) when a connection has
already been established, as opposed to a real connection failure (which
still returns -1).

Bug: 74411879
Test: Opened a socket, tried to adb connect to it,
      got "failed to connect to localhost:1337"

Change-Id: Ic216ddef7f28eb43ca750f9e51d068c077d54b07
This commit is contained in:
Luis Hector Chavez 2018-04-17 14:09:21 -07:00
parent ca10ecb3ae
commit 5d39585255
2 changed files with 7 additions and 3 deletions

View file

@ -974,7 +974,7 @@ int register_socket_transport(int s, const char* serial, int port, int local) {
VLOG(TRANSPORT) << "socket transport " << transport->serial
<< " is already in pending_list and fails to register";
delete t;
return -1;
return -EALREADY;
}
}
@ -983,7 +983,7 @@ int register_socket_transport(int s, const char* serial, int port, int local) {
VLOG(TRANSPORT) << "socket transport " << transport->serial
<< " is already in transport_list and fails to register";
delete t;
return -1;
return -EALREADY;
}
}

View file

@ -101,7 +101,11 @@ void connect_device(const std::string& address, std::string* response) {
int ret = register_socket_transport(fd, serial.c_str(), port, 0);
if (ret < 0) {
adb_close(fd);
*response = android::base::StringPrintf("already connected to %s", serial.c_str());
if (ret == -EALREADY) {
*response = android::base::StringPrintf("already connected to %s", serial.c_str());
} else {
*response = android::base::StringPrintf("failed to connect to %s", serial.c_str());
}
} else {
*response = android::base::StringPrintf("connected to %s", serial.c_str());
}