| 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"; |
| 11 import "dart:io"; | 11 import "dart:io"; |
| 12 import "dart:isolate"; | 12 import "dart:isolate"; |
| 13 | 13 |
| 14 void testCancelResubscribeServerSocket(int socketCount, int backlog) { | 14 void testCancelResubscribeServerSocket(int socketCount, int backlog) { |
| 15 var acceptCount = 0; | 15 var acceptCount = 0; |
| 16 var doneCount = 0; | 16 var doneCount = 0; |
| 17 var closeCount = 0; | 17 var closeCount = 0; |
| 18 var errorCount = 0; | 18 var errorCount = 0; |
| 19 var earlyErrorCount = 0; |
| 19 | 20 |
| 20 ReceivePort port = new ReceivePort(); | 21 ReceivePort port = new ReceivePort(); |
| 21 | 22 |
| 22 RawServerSocket.bind("127.0.0.1", 0, backlog).then((server) { | 23 RawServerSocket.bind("127.0.0.1", 0, backlog).then((server) { |
| 23 Expect.isTrue(server.port > 0); | 24 Expect.isTrue(server.port > 0); |
| 24 | 25 |
| 25 void checkDone() { | 26 void checkDone() { |
| 26 if (doneCount == socketCount && | 27 if (doneCount + earlyErrorCount == socketCount && |
| 27 closeCount + errorCount == socketCount) { | 28 closeCount + errorCount + earlyErrorCount == socketCount) { |
| 28 port.close(); | 29 port.close(); |
| 29 } | 30 } |
| 30 } | 31 } |
| 31 | 32 |
| 32 var subscription; | 33 var subscription; |
| 33 subscription = server.listen((client) { | 34 subscription = server.listen((client) { |
| 34 client.writeEventsEnabled = false; | 35 client.writeEventsEnabled = false; |
| 35 client.listen((event) { | 36 client.listen((event) { |
| 36 switch(event) { | 37 switch(event) { |
| 37 case RawSocketEvent.READ: | 38 case RawSocketEvent.READ: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 doneCount++; | 84 doneCount++; |
| 84 checkDone(); | 85 checkDone(); |
| 85 }, | 86 }, |
| 86 onError: (e) { | 87 onError: (e) { |
| 87 // "Connection reset by peer" errors are handled here. | 88 // "Connection reset by peer" errors are handled here. |
| 88 errorCount++; | 89 errorCount++; |
| 89 checkDone(); | 90 checkDone(); |
| 90 }); | 91 }); |
| 91 }).catchError((e) { | 92 }).catchError((e) { |
| 92 // "Connection actively refused by host" errors are handled here. | 93 // "Connection actively refused by host" errors are handled here. |
| 93 errorCount++; | 94 earlyErrorCount++; |
| 94 checkDone(); | 95 checkDone(); |
| 95 }); | 96 }); |
| 96 } | 97 } |
| 97 }); | 98 }); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void main() { | 101 void main() { |
| 101 testCancelResubscribeServerSocket(10, 20); | 102 testCancelResubscribeServerSocket(10, 20); |
| 102 testCancelResubscribeServerSocket(20, 5); | 103 testCancelResubscribeServerSocket(20, 5); |
| 103 } | 104 } |
| OLD | NEW |