Remove the workaround for issue 19815 in http_multi_server.

This releases http_multi_server 1.0.2.

R=rnystrom@google.com
BUG=20257

Review URL: https://codereview.chromium.org//433593002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38755 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac00908..8cab523 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.2
+
+* Remove the workaround for [issue 19815][].
+
 ## 1.0.1
 
 * Ignore errors from one of the servers if others are still bound. In
diff --git a/lib/http_multi_server.dart b/lib/http_multi_server.dart
index da12888..c055367 100644
--- a/lib/http_multi_server.dart
+++ b/lib/http_multi_server.dart
@@ -99,15 +99,20 @@
   /// [HttpServer.bindSecure].
   static Future<HttpServer> _loopback(int port,
       Future<HttpServer> bind(InternetAddress address, int port)) {
-    return bind(InternetAddress.LOOPBACK_IP_V4, port).then((v4Server) {
+    return Future.wait([
+      supportsIpV6,
+      bind(InternetAddress.LOOPBACK_IP_V4, port)
+    ]).then((results) {
+      var supportsIpV6 = results[0];
+      var v4Server = results[1];
+
+      if (!supportsIpV6) return v4Server;
+
       // Reuse the IPv4 server's port so that if [port] is 0, both servers use
       // the same ephemeral port.
       return bind(InternetAddress.LOOPBACK_IP_V6, v4Server.port)
-          .then((v6Server) => new HttpMultiServer([v4Server, v6Server]))
-          .catchError((error) {
-        // If we fail to bind to IPv6, just use IPv4.
-        if (error is SocketException) return v4Server;
-        throw error;
+          .then((v6Server) {
+        return new HttpMultiServer([v4Server, v6Server]);
       });
     });
   }
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index d615975..9e95aba 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -7,8 +7,6 @@
 import 'dart:async';
 import 'dart:io';
 
-// TODO(nweiz): Revert this to the version of [mergeStreams] found elsewhere in
-// the repo once issue 19815 is fixed in dart:io.
 /// Merges all streams in [streams] into a single stream that emits all of their
 /// values.
 ///
@@ -20,17 +18,9 @@
   controller = new StreamController(onListen: () {
     for (var stream in streams) {
       var subscription;
-      subscription = stream.listen(controller.add, onError: (error, trace) {
-        if (subscriptions.length == 1) {
-          // If the last subscription errored, pass it on.
-          controller.addError(error, trace);
-        } else {
-          // If only one of the subscriptions has an error (usually IPv6 failing
-          // late), then just remove that subscription and ignore the error.
-          subscriptions.remove(subscription);
-          subscription.cancel();
-        }
-      }, onDone: () {
+      subscription = stream.listen(controller.add,
+          onError: controller.addError,
+          onDone: () {
         subscriptions.remove(subscription);
         if (subscriptions.isEmpty) controller.close();
       });
@@ -52,3 +42,21 @@
 
   return controller.stream;
 }
+
+/// A cache for [supportsIpV6].
+bool _supportsIpV6;
+
+/// Returns whether this computer supports binding to IPv6 addresses.
+Future<bool> get supportsIpV6 {
+  if (_supportsIpV6 != null) return new Future.value(_supportsIpV6);
+
+  return ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0).then((socket) {
+    _supportsIpV6 = true;
+    socket.close();
+    return true;
+  }).catchError((error) {
+    if (error is! SocketException) throw error;
+    _supportsIpV6 = false;
+    return false;
+  });
+}
diff --git a/pubspec.yaml b/pubspec.yaml
index 2bdb4a2..c7361d4 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: http_multi_server
-version: 1.0.1
+version: 1.0.2
 author: "Dart Team <misc@dartlang.org>"
 homepage: http://www.dartlang.org
 description:
@@ -8,4 +8,4 @@
   unittest: ">=0.11.0 <0.12.0"
   http: ">=0.11.0 <0.12.0"
 environment:
-  sdk: ">=1.4.0 <2.0.0"
+  sdk: ">=1.6.0-dev.6.0 <2.0.0"
diff --git a/test/http_multi_server_test.dart b/test/http_multi_server_test.dart
index 0140ee7..a3d9062 100644
--- a/test/http_multi_server_test.dart
+++ b/test/http_multi_server_test.dart
@@ -108,7 +108,7 @@
       expect(http.read("http://127.0.0.1:${server.port}/"),
           completion(equals("got request")));
 
-      return _supportsIpV6.then((supportsIpV6) {
+      return supportsIpV6.then((supportsIpV6) {
         if (!supportsIpV6) return;
         expect(http.read("http://[::1]:${server.port}/"),
             completion(equals("got request")));
@@ -117,26 +117,6 @@
   });
 }
 
-/// A cache for [supportsIpV6].
-bool _supportsIpV6Cache;
-
-// TODO(nweiz): This is known to be inaccurate on Windows machines with IPv6
-// disabled (issue 19815). Tests will fail on such machines.
-/// Returns whether this computer supports binding to IPv6 addresses.
-Future<bool> get _supportsIpV6 {
-  if (_supportsIpV6Cache != null) return new Future.value(_supportsIpV6Cache);
-
-  return ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0).then((socket) {
-    _supportsIpV6Cache = true;
-    socket.close();
-    return true;
-  }).catchError((error) {
-    if (error is! SocketException) throw error;
-    _supportsIpV6Cache = false;
-    return false;
-  });
-}
-
 /// Makes a GET request to the root of [server] and returns the response.
 Future<http.Response> _get(HttpServer server) => http.get(_urlFor(server));