Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: lib/src/util/io.dart

Issue 1269223004: Expose PhantomJS's remote debugger URL. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Fix a test. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/runner/browser/phantom_js.dart ('k') | test/runner/pause_after_load_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/util/io.dart
diff --git a/lib/src/util/io.dart b/lib/src/util/io.dart
index 2c008a97f4f7e5784c809ed00a48327f0a2614ad..a2b23d8f61e2885017da29afa36bcccb86e3721d 100644
--- a/lib/src/util/io.dart
+++ b/lib/src/util/io.dart
@@ -208,11 +208,19 @@ String libraryPath(Symbol libraryName, {String packageRoot}) {
Future getUnusedPort(tryPort(int port)) {
var value;
return Future.doWhile(() async {
- var socket = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
- var port = socket.port;
- await socket.close();
-
- value = await tryPort(port);
+ value = await tryPort(await getUnsafeUnusedPort());
return value == null;
}).then((_) => value);
}
+
+/// Returns a port that is probably, but not definitely, not in use.
+///
+/// This has a built-in race condition: another process may bind this port at
+/// any time after this call has returned. If at all possible, callers should
+/// use [getUnusedPort] instead.
+Future<int> getUnsafeUnusedPort() async {
+ var socket = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
+ var port = socket.port;
+ await socket.close();
+ return port;
+}
« no previous file with comments | « lib/src/runner/browser/phantom_js.dart ('k') | test/runner/pause_after_load_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698