Support IPv6-only hosts in vmservice_test.dart. (#12985)

If we fail to bind to IPv4 loopback, try IPv6. Some hosts only support IPv6,
causing the test in vmservice_test.dart to fail, since it couldn't find an
available port.
This commit is contained in:
Jakob Andersen
2017-11-11 21:33:40 +01:00
committed by GitHub
parent 96942bc797
commit 9be85b6b4b

View File

@@ -61,7 +61,12 @@ class HostPortScanner extends PortScanner {
@override
Future<int> findAvailablePort() async {
final ServerSocket socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
ServerSocket socket;
try {
socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
} on SocketException {
socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0, v6Only: true);
}
final int port = socket.port;
await socket.close();
return port;