diff options
-rw-r--r-- | adb/transport.cpp | 16 | ||||
-rw-r--r-- | adb/transport.h | 2 | ||||
-rw-r--r-- | adb/transport_local.cpp | 9 |
3 files changed, 10 insertions, 17 deletions
diff --git a/adb/transport.cpp b/adb/transport.cpp index 922200826..3c74c7591 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp | |||
@@ -1190,17 +1190,11 @@ void close_usb_devices() { | |||
1190 | } | 1190 | } |
1191 | #endif // ADB_HOST | 1191 | #endif // ADB_HOST |
1192 | 1192 | ||
1193 | int register_socket_transport(unique_fd s, const char* serial, int port, int local, | 1193 | int register_socket_transport(unique_fd s, std::string serial, int port, int local, |
1194 | atransport::ReconnectCallback reconnect) { | 1194 | atransport::ReconnectCallback reconnect) { |
1195 | atransport* t = new atransport(std::move(reconnect), kCsOffline); | 1195 | atransport* t = new atransport(std::move(reconnect), kCsOffline); |
1196 | 1196 | ||
1197 | if (!serial) { | 1197 | D("transport: %s init'ing for socket %d, on port %d", serial.c_str(), s.get(), port); |
1198 | char buf[32]; | ||
1199 | snprintf(buf, sizeof(buf), "T-%p", t); | ||
1200 | serial = buf; | ||
1201 | } | ||
1202 | |||
1203 | D("transport: %s init'ing for socket %d, on port %d", serial, s.get(), port); | ||
1204 | if (init_socket_transport(t, std::move(s), port, local) < 0) { | 1198 | if (init_socket_transport(t, std::move(s), port, local) < 0) { |
1205 | delete t; | 1199 | delete t; |
1206 | return -1; | 1200 | return -1; |
@@ -1208,7 +1202,7 @@ int register_socket_transport(unique_fd s, const char* serial, int port, int loc | |||
1208 | 1202 | ||
1209 | std::unique_lock<std::recursive_mutex> lock(transport_lock); | 1203 | std::unique_lock<std::recursive_mutex> lock(transport_lock); |
1210 | for (const auto& transport : pending_list) { | 1204 | for (const auto& transport : pending_list) { |
1211 | if (strcmp(serial, transport->serial.c_str()) == 0) { | 1205 | if (serial == transport->serial) { |
1212 | VLOG(TRANSPORT) << "socket transport " << transport->serial | 1206 | VLOG(TRANSPORT) << "socket transport " << transport->serial |
1213 | << " is already in pending_list and fails to register"; | 1207 | << " is already in pending_list and fails to register"; |
1214 | delete t; | 1208 | delete t; |
@@ -1217,7 +1211,7 @@ int register_socket_transport(unique_fd s, const char* serial, int port, int loc | |||
1217 | } | 1211 | } |
1218 | 1212 | ||
1219 | for (const auto& transport : transport_list) { | 1213 | for (const auto& transport : transport_list) { |
1220 | if (strcmp(serial, transport->serial.c_str()) == 0) { | 1214 | if (serial == transport->serial) { |
1221 | VLOG(TRANSPORT) << "socket transport " << transport->serial | 1215 | VLOG(TRANSPORT) << "socket transport " << transport->serial |
1222 | << " is already in transport_list and fails to register"; | 1216 | << " is already in transport_list and fails to register"; |
1223 | delete t; | 1217 | delete t; |
@@ -1225,8 +1219,8 @@ int register_socket_transport(unique_fd s, const char* serial, int port, int loc | |||
1225 | } | 1219 | } |
1226 | } | 1220 | } |
1227 | 1221 | ||
1222 | t->serial = std::move(serial); | ||
1228 | pending_list.push_front(t); | 1223 | pending_list.push_front(t); |
1229 | t->serial = serial; | ||
1230 | 1224 | ||
1231 | lock.unlock(); | 1225 | lock.unlock(); |
1232 | 1226 | ||
diff --git a/adb/transport.h b/adb/transport.h index 1844ae8aa..4bfc2ce2b 100644 --- a/adb/transport.h +++ b/adb/transport.h | |||
@@ -364,7 +364,7 @@ void register_usb_transport(usb_handle* h, const char* serial, | |||
364 | void connect_device(const std::string& address, std::string* response); | 364 | void connect_device(const std::string& address, std::string* response); |
365 | 365 | ||
366 | /* cause new transports to be init'd and added to the list */ | 366 | /* cause new transports to be init'd and added to the list */ |
367 | int register_socket_transport(unique_fd s, const char* serial, int port, int local, | 367 | int register_socket_transport(unique_fd s, std::string serial, int port, int local, |
368 | atransport::ReconnectCallback reconnect); | 368 | atransport::ReconnectCallback reconnect); |
369 | 369 | ||
370 | // This should only be used for transports with connection_state == kCsNoPerm. | 370 | // This should only be used for transports with connection_state == kCsNoPerm. |
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp index 9398cebe8..3b1552e3a 100644 --- a/adb/transport_local.cpp +++ b/adb/transport_local.cpp | |||
@@ -125,8 +125,7 @@ void connect_device(const std::string& address, std::string* response) { | |||
125 | return init_socket_transport(t, std::move(fd), port, 0) >= 0; | 125 | return init_socket_transport(t, std::move(fd), port, 0) >= 0; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | int ret = | 128 | int ret = register_socket_transport(std::move(fd), serial, port, 0, std::move(reconnect)); |
129 | register_socket_transport(std::move(fd), serial.c_str(), port, 0, std::move(reconnect)); | ||
130 | if (ret < 0) { | 129 | if (ret < 0) { |
131 | if (ret == -EALREADY) { | 130 | if (ret == -EALREADY) { |
132 | *response = android::base::StringPrintf("already connected to %s", serial.c_str()); | 131 | *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 | |||
162 | close_on_exec(fd.get()); | 161 | close_on_exec(fd.get()); |
163 | disable_tcp_nagle(fd.get()); | 162 | disable_tcp_nagle(fd.get()); |
164 | std::string serial = getEmulatorSerialString(console_port); | 163 | std::string serial = getEmulatorSerialString(console_port); |
165 | if (register_socket_transport(std::move(fd), serial.c_str(), adb_port, 1, | 164 | if (register_socket_transport(std::move(fd), std::move(serial), adb_port, 1, |
166 | [](atransport*) { return false; }) == 0) { | 165 | [](atransport*) { return false; }) == 0) { |
167 | return 0; | 166 | return 0; |
168 | } | 167 | } |
@@ -265,7 +264,7 @@ static void server_socket_thread(int port) { | |||
265 | close_on_exec(fd.get()); | 264 | close_on_exec(fd.get()); |
266 | disable_tcp_nagle(fd.get()); | 265 | disable_tcp_nagle(fd.get()); |
267 | std::string serial = android::base::StringPrintf("host-%d", fd.get()); | 266 | std::string serial = android::base::StringPrintf("host-%d", fd.get()); |
268 | register_socket_transport(std::move(fd), serial.c_str(), port, 1, | 267 | register_socket_transport(std::move(fd), std::move(serial), port, 1, |
269 | [](atransport*) { return false; }); | 268 | [](atransport*) { return false; }); |
270 | } | 269 | } |
271 | } | 270 | } |
@@ -362,7 +361,7 @@ static void qemu_socket_thread(int port) { | |||
362 | * exchange. */ | 361 | * exchange. */ |
363 | std::string serial = android::base::StringPrintf("host-%d", fd.get()); | 362 | std::string serial = android::base::StringPrintf("host-%d", fd.get()); |
364 | WriteFdExactly(fd.get(), _start_req, strlen(_start_req)); | 363 | WriteFdExactly(fd.get(), _start_req, strlen(_start_req)); |
365 | register_socket_transport(std::move(fd), serial.c_str(), port, 1, | 364 | register_socket_transport(std::move(fd), std::move(serial), port, 1, |
366 | [](atransport*) { return false; }); | 365 | [](atransport*) { return false; }); |
367 | } | 366 | } |
368 | 367 | ||