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

Unified Diff: pkg/http_multi_server/lib/src/utils.dart

Issue 317803003: Add a LICENSE file to pkg/http_multi_server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | « pkg/http_multi_server/lib/http_multi_server.dart ('k') | pkg/http_multi_server/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_multi_server/lib/src/utils.dart
diff --git a/pkg/http_multi_server/lib/src/utils.dart b/pkg/http_multi_server/lib/src/utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9e95aba5f9d82612e7bf2d3632c762dd156e8ced
--- /dev/null
+++ b/pkg/http_multi_server/lib/src/utils.dart
@@ -0,0 +1,62 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library http_multi_server.utils;
+
+import 'dart:async';
+import 'dart:io';
+
+/// Merges all streams in [streams] into a single stream that emits all of their
+/// values.
+///
+/// The returned stream will be closed only when every stream in [streams] is
+/// closed.
+Stream mergeStreams(Iterable<Stream> streams) {
+ var subscriptions = new Set();
+ var controller;
+ controller = new StreamController(onListen: () {
+ for (var stream in streams) {
+ var subscription;
+ subscription = stream.listen(controller.add,
+ onError: controller.addError,
+ onDone: () {
+ subscriptions.remove(subscription);
+ if (subscriptions.isEmpty) controller.close();
+ });
+ subscriptions.add(subscription);
+ }
+ }, onCancel: () {
+ for (var subscription in subscriptions) {
+ subscription.cancel();
+ }
+ }, onPause: () {
+ for (var subscription in subscriptions) {
+ subscription.pause();
+ }
+ }, onResume: () {
+ for (var subscription in subscriptions) {
+ subscription.resume();
+ }
+ }, sync: true);
+
+ 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;
+ });
+}
« no previous file with comments | « pkg/http_multi_server/lib/http_multi_server.dart ('k') | pkg/http_multi_server/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698