| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Test creating a large number of socket connections. | 5 // Test creating a large number of socket connections. |
| 6 | 6 |
| 7 #library("SocketManyConnectionsTest"); | 7 #library("SocketManyConnectionsTest"); |
| 8 #import("dart:io"); | 8 #import("dart:io"); |
| 9 #import("dart:isolate"); | 9 #import("dart:isolate"); |
| 10 #source("TestingServer.dart"); | 10 #source("TestingServer.dart"); |
| 11 | 11 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 32 for (int i = 0; i < CONNECTIONS; i++) { | 32 for (int i = 0; i < CONNECTIONS; i++) { |
| 33 _sockets[i].close(); | 33 _sockets[i].close(); |
| 34 } | 34 } |
| 35 shutdown(); | 35 shutdown(); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 for (int i = 0; i < CONNECTIONS; i++) { | 39 for (int i = 0; i < CONNECTIONS; i++) { |
| 40 _sockets[i] = new Socket(TestingServer.HOST, _port); | 40 _sockets[i] = new Socket(TestingServer.HOST, _port); |
| 41 if (_sockets[i] !== null) { | 41 if (_sockets[i] !== null) { |
| 42 _sockets[i].connectHandler = connectHandler; | 42 _sockets[i].onConnect = connectHandler; |
| 43 } else { | 43 } else { |
| 44 Expect.fail("socket creation failed"); | 44 Expect.fail("socket creation failed"); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 void start() { | 49 void start() { |
| 50 _receivePort.receive((var message, SendPort replyTo) { | 50 _receivePort.receive((var message, SendPort replyTo) { |
| 51 _port = message; | 51 _port = message; |
| 52 run(); | 52 run(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 74 void closeHandler() { | 74 void closeHandler() { |
| 75 connection.close(); | 75 connection.close(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void errorHandler() { | 78 void errorHandler() { |
| 79 print("Socket error"); | 79 print("Socket error"); |
| 80 connection.close(); | 80 connection.close(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 _connections++; | 83 _connections++; |
| 84 connection.closeHandler = closeHandler; | 84 connection.onClosed = closeHandler; |
| 85 connection.errorHandler = errorHandler; | 85 connection.onError = errorHandler; |
| 86 } | 86 } |
| 87 | 87 |
| 88 int _connections = 0; | 88 int _connections = 0; |
| 89 } | 89 } |
| 90 | 90 |
| 91 main() { | 91 main() { |
| 92 SocketManyConnectionsTest test = new SocketManyConnectionsTest.start(); | 92 SocketManyConnectionsTest test = new SocketManyConnectionsTest.start(); |
| 93 } | 93 } |
| OLD | NEW |