int init_socket_transport(atransport *t, int s, int adb_port, int local) { int fail = 0; t->SetKickFunction(remote_kick); t->close = remote_close; t->read_from_remote = remote_read; t->write_to_remote = remote_write; t->sfd = s; t->sync_token = 1; t->connection_state = kCsOffline; t->type = kTransportLocal; #if ADB_HOST if (local) { std::lock_guard<std::mutex> lock(local_transports_lock); t->SetLocalPortForEmulator(adb_port); atransport* existing_transport = find_emulator_transport_by_adb_port_locked(adb_port); int index = get_available_local_transport_index_locked(); if (existing_transport != NULL) { D("local transport for port %d already registered (%p)?", adb_port, existing_transport); fail = -1; } else if (index < 0) { // Too many emulators. D("cannot register more emulators. Maximum is %d", ADB_LOCAL_TRANSPORT_MAX); fail = -1; } else { local_transports[index] = t; } } #endif return fail; }
atransport* find_emulator_transport_by_adb_port(int adb_port) { adb_mutex_lock( &local_transports_lock ); atransport* result = find_emulator_transport_by_adb_port_locked(adb_port); adb_mutex_unlock( &local_transports_lock ); return result; }
int init_socket_transport(atransport *t, int s, int adb_port, int local) { int fail = 0; t->kick = remote_kick; t->close = remote_close; t->read_from_remote = remote_read; t->write_to_remote = remote_write; t->sfd = s; t->sync_token = 1; t->connection_state = CS_OFFLINE; t->type = kTransportLocal; t->adb_port = 0; #if ADB_HOST if (HOST && local) { adb_mutex_lock( &local_transports_lock ); { t->adb_port = adb_port; atransport* existing_transport = find_emulator_transport_by_adb_port_locked(adb_port); int index = get_available_local_transport_index_locked(); if (existing_transport != NULL) { D("local transport for port %d already registered (%p)?\n", adb_port, existing_transport); fail = -1; } else if (index < 0) { // Too many emulators. D("cannot register more emulators. Maximum is %d\n", ADB_LOCAL_TRANSPORT_MAX); fail = -1; } else { local_transports[index] = t; } } adb_mutex_unlock( &local_transports_lock ); } #endif return fail; }
atransport* find_emulator_transport_by_adb_port(int adb_port) { std::lock_guard<std::mutex> lock(local_transports_lock); atransport* result = find_emulator_transport_by_adb_port_locked(adb_port); return result; }