Use ephemeral ports for iOS port forwarding (#60381)

This commit is contained in:
Jenn Magder
2020-06-26 15:02:05 -07:00
committed by GitHub
parent 025463f463
commit a4fa61b4f1
3 changed files with 30 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ import '../artifacts.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
import '../base/os.dart';
import '../base/platform.dart';
import '../base/process.dart';
import '../base/utils.dart';
@@ -493,6 +494,7 @@ class IOSDevice extends Device {
dyLdLibEntry: globals.cache.dyLdLibEntry,
id: id,
iproxyPath: _iproxyPath,
operatingSystemUtils: globals.os,
);
@visibleForTesting
@@ -763,11 +765,13 @@ class IOSDevicePortForwarder extends DevicePortForwarder {
@required MapEntry<String, String> dyLdLibEntry,
@required String id,
@required String iproxyPath,
@required OperatingSystemUtils operatingSystemUtils,
}) : _logger = logger,
_dyLdLibEntry = dyLdLibEntry,
_id = id,
_iproxyPath = iproxyPath,
_processUtils = ProcessUtils(processManager: processManager, logger: logger);
_processUtils = ProcessUtils(processManager: processManager, logger: logger),
_operatingSystemUtils = operatingSystemUtils;
/// Create a [IOSDevicePortForwarder] for testing.
///
@@ -779,6 +783,7 @@ class IOSDevicePortForwarder extends DevicePortForwarder {
@required ProcessManager processManager,
@required Logger logger,
String id,
OperatingSystemUtils operatingSystemUtils,
}) {
return IOSDevicePortForwarder(
processManager: processManager,
@@ -788,6 +793,7 @@ class IOSDevicePortForwarder extends DevicePortForwarder {
dyLdLibEntry: const MapEntry<String, String>(
'DYLD_LIBRARY_PATH', '/path/to/libs',
),
operatingSystemUtils: operatingSystemUtils,
);
}
@@ -796,6 +802,7 @@ class IOSDevicePortForwarder extends DevicePortForwarder {
final MapEntry<String, String> _dyLdLibEntry;
final String _id;
final String _iproxyPath;
final OperatingSystemUtils _operatingSystemUtils;
@override
List<ForwardedPort> forwardedPorts = <ForwardedPort>[];
@@ -811,7 +818,9 @@ class IOSDevicePortForwarder extends DevicePortForwarder {
Future<int> forward(int devicePort, { int hostPort }) async {
final bool autoselect = hostPort == null || hostPort == 0;
if (autoselect) {
hostPort = 1024;
final int freePort = await _operatingSystemUtils?.findFreePort();
// Dynamic port range 49152 - 65535.
hostPort = freePort == null || freePort == 0 ? 49152 : freePort;
}
Process process;