| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions= | 5 // VMOptions= |
| 6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
| 7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
| 8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
| 9 | 9 |
| 10 import "dart:async"; | 10 import "dart:async"; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 resumed = true; | 256 resumed = true; |
| 257 for (int i = connectCount; i < socketCount; i++) { | 257 for (int i = connectCount; i < socketCount; i++) { |
| 258 RawSocket.connect("127.0.0.1", server.port).then((_) {}); | 258 RawSocket.connect("127.0.0.1", server.port).then((_) {}); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 }); | 261 }); |
| 262 } | 262 } |
| 263 }); | 263 }); |
| 264 } | 264 } |
| 265 | 265 |
| 266 testCancelResubscribeServerSocket() { | 266 void testPauseSocket() { |
| 267 const int socketCount = 10; | |
| 268 var acceptCount = 0; | |
| 269 var doneCount = 0; | |
| 270 var closeCount = 0; | |
| 271 var errorCount = 0; | |
| 272 | |
| 273 ReceivePort port = new ReceivePort(); | |
| 274 | |
| 275 RawServerSocket.bind().then((server) { | |
| 276 Expect.isTrue(server.port > 0); | |
| 277 | |
| 278 void checkDone() { | |
| 279 if (doneCount == socketCount && | |
| 280 closeCount + errorCount == socketCount) { | |
| 281 port.close(); | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 // Subscribe the server socket. Then cancel subscription and | |
| 286 // subscribe again. | |
| 287 var subscription; | |
| 288 subscription = server.listen((client) { | |
| 289 if (++acceptCount == socketCount / 2) { | |
| 290 subscription.cancel(); | |
| 291 Timer.run(() { | |
| 292 subscription = server.listen((_) { | |
| 293 // Close on cancel, so no more events. | |
| 294 Expect.fail("Event after closed through cancel"); | |
| 295 }); | |
| 296 }); | |
| 297 } | |
| 298 // Close the client socket. | |
| 299 client.close(); | |
| 300 }); | |
| 301 | |
| 302 // Connect a number of sockets. | |
| 303 for (int i = 0; i < socketCount; i++) { | |
| 304 RawSocket.connect("127.0.0.1", server.port).then((socket) { | |
| 305 socket.writeEventsEnabled = false; | |
| 306 var subscription; | |
| 307 subscription = socket.listen((event) { | |
| 308 Expect.equals(RawSocketEvent.READ_CLOSED, event); | |
| 309 socket.close(); | |
| 310 closeCount++; | |
| 311 checkDone(); | |
| 312 }, | |
| 313 onDone: () { doneCount++; checkDone(); }, | |
| 314 onError: (e) { errorCount++; checkDone(); }); | |
| 315 }); | |
| 316 } | |
| 317 }); | |
| 318 } | |
| 319 | |
| 320 testPauseSocket() { | |
| 321 const messageSize = 1000; | 267 const messageSize = 1000; |
| 322 const loopCount = 10; | 268 const loopCount = 10; |
| 323 Completer connected = new Completer(); | 269 Completer connected = new Completer(); |
| 324 int pauseResumeCount = 0; | 270 int pauseResumeCount = 0; |
| 325 int bytesWritten = 0; | 271 int bytesWritten = 0; |
| 326 int bytesRead = 0; | 272 int bytesRead = 0; |
| 327 var writeSubscription; | 273 var writeSubscription; |
| 328 var readSubscription; | 274 var readSubscription; |
| 329 | 275 |
| 330 ReceivePort port = new ReceivePort(); | 276 ReceivePort port = new ReceivePort(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 main() { | 346 main() { |
| 401 testArguments(); | 347 testArguments(); |
| 402 testSimpleBind(); | 348 testSimpleBind(); |
| 403 testCloseOneEnd("client"); | 349 testCloseOneEnd("client"); |
| 404 testCloseOneEnd("server"); | 350 testCloseOneEnd("server"); |
| 405 testInvalidBind(); | 351 testInvalidBind(); |
| 406 testSimpleConnect(); | 352 testSimpleConnect(); |
| 407 testServerListenAfterConnect(); | 353 testServerListenAfterConnect(); |
| 408 testSimpleReadWrite(); | 354 testSimpleReadWrite(); |
| 409 testPauseServerSocket(); | 355 testPauseServerSocket(); |
| 410 testCancelResubscribeServerSocket(); | |
| 411 testPauseSocket(); | 356 testPauseSocket(); |
| 412 } | 357 } |
| OLD | NEW |