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

Unified Diff: tests/standalone/io/socket_reuse_port_test.dart

Issue 25511002: Add reusePort argument to ServerSocket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mac os X version. Created 7 years, 3 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 | « sdk/lib/io/socket.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/socket_reuse_port_test.dart
diff --git a/tests/standalone/io/socket_reuse_port_test.dart b/tests/standalone/io/socket_reuse_port_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..09893f339f8e4366bbbb6e5707dbe74929bcebda
--- /dev/null
+++ b/tests/standalone/io/socket_reuse_port_test.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2013, 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.
+
+import "dart:async";
+import "dart:io";
+
+
+void testReuseSocket(int numConnections, int numServers) {
+ ServerSocket.bind('localhost', 0, reusePort: true).then((server) {
+ var servers = [];
+ for (int i = 1; i < numServers; i++) {
+ servers.add(ServerSocket.bind('localhost', server.port, reusePort: true));
+ }
+ Future.wait(servers).then((servers) {
+ servers = [server]..addAll(servers);
+ for (var server in servers) {
+ server.listen((socket) {
+ socket.pipe(socket);
+ });
+ }
+ var connections = [];
+ for (int i = 0; i < numConnections; i++) {
+ connections.add(
+ Socket.connect('localhost', server.port)
+ .then((socket) => socket.close())
+ .then((socket) => socket.listen(null).asFuture()));
+ }
+ Future.wait(connections).then((_) {
+ for (var server in servers) {
+ server.close();
+ }
+ });
+ });
+ }).catchError((e) {
+ print("reusePort is not supported: $e");
+ });
+}
+
+void main() {
+ testReuseSocket(1, 1);
+ testReuseSocket(10, 1);
+ testReuseSocket(10, 10);
+ testReuseSocket(100, 10);
+}
« no previous file with comments | « sdk/lib/io/socket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698