Merge "adb: delete hellish hodgepodge."
am: acc0a90869
Change-Id: I966ae7f468885ca2c9d1d633ef40def3a3e8627a
This commit is contained in:
commit
fbe62c5aaf
3 changed files with 10 additions and 17 deletions
|
@ -1190,17 +1190,11 @@ void close_usb_devices() {
|
|||
}
|
||||
#endif // ADB_HOST
|
||||
|
||||
int register_socket_transport(unique_fd s, const char* serial, int port, int local,
|
||||
int register_socket_transport(unique_fd s, std::string serial, int port, int local,
|
||||
atransport::ReconnectCallback reconnect) {
|
||||
atransport* t = new atransport(std::move(reconnect), kCsOffline);
|
||||
|
||||
if (!serial) {
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "T-%p", t);
|
||||
serial = buf;
|
||||
}
|
||||
|
||||
D("transport: %s init'ing for socket %d, on port %d", serial, s.get(), port);
|
||||
D("transport: %s init'ing for socket %d, on port %d", serial.c_str(), s.get(), port);
|
||||
if (init_socket_transport(t, std::move(s), port, local) < 0) {
|
||||
delete t;
|
||||
return -1;
|
||||
|
@ -1208,7 +1202,7 @@ int register_socket_transport(unique_fd s, const char* serial, int port, int loc
|
|||
|
||||
std::unique_lock<std::recursive_mutex> lock(transport_lock);
|
||||
for (const auto& transport : pending_list) {
|
||||
if (strcmp(serial, transport->serial.c_str()) == 0) {
|
||||
if (serial == transport->serial) {
|
||||
VLOG(TRANSPORT) << "socket transport " << transport->serial
|
||||
<< " is already in pending_list and fails to register";
|
||||
delete t;
|
||||
|
@ -1217,7 +1211,7 @@ int register_socket_transport(unique_fd s, const char* serial, int port, int loc
|
|||
}
|
||||
|
||||
for (const auto& transport : transport_list) {
|
||||
if (strcmp(serial, transport->serial.c_str()) == 0) {
|
||||
if (serial == transport->serial) {
|
||||
VLOG(TRANSPORT) << "socket transport " << transport->serial
|
||||
<< " is already in transport_list and fails to register";
|
||||
delete t;
|
||||
|
@ -1225,8 +1219,8 @@ int register_socket_transport(unique_fd s, const char* serial, int port, int loc
|
|||
}
|
||||
}
|
||||
|
||||
t->serial = std::move(serial);
|
||||
pending_list.push_front(t);
|
||||
t->serial = serial;
|
||||
|
||||
lock.unlock();
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ void register_usb_transport(usb_handle* h, const char* serial,
|
|||
void connect_device(const std::string& address, std::string* response);
|
||||
|
||||
/* cause new transports to be init'd and added to the list */
|
||||
int register_socket_transport(unique_fd s, const char* serial, int port, int local,
|
||||
int register_socket_transport(unique_fd s, std::string serial, int port, int local,
|
||||
atransport::ReconnectCallback reconnect);
|
||||
|
||||
// This should only be used for transports with connection_state == kCsNoPerm.
|
||||
|
|
|
@ -125,8 +125,7 @@ void connect_device(const std::string& address, std::string* response) {
|
|||
return init_socket_transport(t, std::move(fd), port, 0) >= 0;
|
||||
};
|
||||
|
||||
int ret =
|
||||
register_socket_transport(std::move(fd), serial.c_str(), port, 0, std::move(reconnect));
|
||||
int ret = register_socket_transport(std::move(fd), serial, port, 0, std::move(reconnect));
|
||||
if (ret < 0) {
|
||||
if (ret == -EALREADY) {
|
||||
*response = android::base::StringPrintf("already connected to %s", serial.c_str());
|
||||
|
@ -162,7 +161,7 @@ int local_connect_arbitrary_ports(int console_port, int adb_port, std::string* e
|
|||
close_on_exec(fd.get());
|
||||
disable_tcp_nagle(fd.get());
|
||||
std::string serial = getEmulatorSerialString(console_port);
|
||||
if (register_socket_transport(std::move(fd), serial.c_str(), adb_port, 1,
|
||||
if (register_socket_transport(std::move(fd), std::move(serial), adb_port, 1,
|
||||
[](atransport*) { return false; }) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -265,7 +264,7 @@ static void server_socket_thread(int port) {
|
|||
close_on_exec(fd.get());
|
||||
disable_tcp_nagle(fd.get());
|
||||
std::string serial = android::base::StringPrintf("host-%d", fd.get());
|
||||
register_socket_transport(std::move(fd), serial.c_str(), port, 1,
|
||||
register_socket_transport(std::move(fd), std::move(serial), port, 1,
|
||||
[](atransport*) { return false; });
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +361,7 @@ static void qemu_socket_thread(int port) {
|
|||
* exchange. */
|
||||
std::string serial = android::base::StringPrintf("host-%d", fd.get());
|
||||
WriteFdExactly(fd.get(), _start_req, strlen(_start_req));
|
||||
register_socket_transport(std::move(fd), serial.c_str(), port, 1,
|
||||
register_socket_transport(std::move(fd), std::move(serial), port, 1,
|
||||
[](atransport*) { return false; });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue