summaryrefslogtreecommitdiffstats
path: root/adb/transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'adb/transport.c')
-rw-r--r--adb/transport.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/adb/transport.c b/adb/transport.c
index b4abb66..224fe55 100644
--- a/adb/transport.c
+++ b/adb/transport.c
@@ -32,6 +32,11 @@ static atransport transport_list = {
.prev = &transport_list,
};
+static atransport pending_list = {
+ .next = &pending_list,
+ .prev = &pending_list,
+};
+
ADB_MUTEX_DEFINE( transport_lock );
#if ADB_TRACE
@@ -645,8 +650,11 @@ static void transport_registration_func(int _fd, unsigned ev, void *data)
}
}
- /* put us on the master device list */
adb_mutex_lock(&transport_lock);
+ /* remove from pending list */
+ t->next->prev = t->prev;
+ t->prev->next = t->next;
+ /* put us on the master device list */
t->next = &transport_list;
t->prev = transport_list.prev;
t->next->prev = t;
@@ -989,9 +997,10 @@ void close_usb_devices()
}
#endif // ADB_HOST
-void register_socket_transport(int s, const char *serial, int port, int local)
+int register_socket_transport(int s, const char *serial, int port, int local)
{
atransport *t = calloc(1, sizeof(atransport));
+ atransport *n;
char buff[32];
if (!serial) {
@@ -999,15 +1008,37 @@ void register_socket_transport(int s, const char *serial, int port, int local)
serial = buff;
}
D("transport: %s init'ing for socket %d, on port %d\n", serial, s, port);
- if ( init_socket_transport(t, s, port, local) < 0 ) {
- adb_close(s);
+ if (init_socket_transport(t, s, port, local) < 0) {
free(t);
- return;
+ return -1;
}
- if(serial) {
- t->serial = strdup(serial);
+
+ adb_mutex_lock(&transport_lock);
+ for (n = pending_list.next; n != &pending_list; n = n->next) {
+ if (n->serial && !strcmp(serial, n->serial)) {
+ adb_mutex_unlock(&transport_lock);
+ free(t);
+ return -1;
+ }
+ }
+
+ for (n = transport_list.next; n != &transport_list; n = n->next) {
+ if (n->serial && !strcmp(serial, n->serial)) {
+ adb_mutex_unlock(&transport_lock);
+ free(t);
+ return -1;
+ }
}
+
+ t->next = &pending_list;
+ t->prev = pending_list.prev;
+ t->next->prev = t;
+ t->prev->next = t;
+ t->serial = strdup(serial);
+ adb_mutex_unlock(&transport_lock);
+
register_transport(t);
+ return 0;
}
#if ADB_HOST
@@ -1077,6 +1108,14 @@ void register_usb_transport(usb_handle *usb, const char *serial, const char *dev
if(devpath) {
t->devpath = strdup(devpath);
}
+
+ adb_mutex_lock(&transport_lock);
+ t->next = &pending_list;
+ t->prev = pending_list.prev;
+ t->next->prev = t;
+ t->prev->next = t;
+ adb_mutex_unlock(&transport_lock);
+
register_transport(t);
}