| OLD | NEW |
| 1 // Copyright (c) 2012, 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 // 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 // Test socket close events. | 10 // Test socket close events. |
| 11 | 11 |
| 12 import "dart:io"; | 12 import 'dart:async'; |
| 13 import "dart:isolate"; | 13 import 'dart:io'; |
| 14 import 'dart:isolate'; |
| 14 | 15 |
| 15 const SERVERSHUTDOWN = -1; | 16 const SERVERSHUTDOWN = -1; |
| 16 const ITERATIONS = 10; | 17 const ITERATIONS = 10; |
| 17 | 18 |
| 18 | 19 |
| 19 class SocketClose { | 20 class SocketClose { |
| 20 | 21 |
| 21 SocketClose.start(this._mode, this._donePort) | 22 SocketClose.start(this._mode, this._donePort) |
| 22 : _receivePort = new ReceivePort(), | 23 : _receivePort = new ReceivePort(), |
| 23 _sendPort = null, | 24 _sendPort = null, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 44 switch (_mode) { | 45 switch (_mode) { |
| 45 case 0: | 46 case 0: |
| 46 case 1: | 47 case 1: |
| 47 case 2: | 48 case 2: |
| 48 Expect.fail("No data expected"); | 49 Expect.fail("No data expected"); |
| 49 break; | 50 break; |
| 50 case 3: | 51 case 3: |
| 51 case 4: | 52 case 4: |
| 52 case 5: | 53 case 5: |
| 53 case 6: | 54 case 6: |
| 54 List<int> b = new List<int>(5); | 55 List<int> b = new List<int>.fixedLength(5); |
| 55 _readBytes += _socket.readList(b, 0, 5); | 56 _readBytes += _socket.readList(b, 0, 5); |
| 56 if ((_readBytes % 5) == 0) { | 57 if ((_readBytes % 5) == 0) { |
| 57 _dataEvents++; | 58 _dataEvents++; |
| 58 } | 59 } |
| 59 break; | 60 break; |
| 60 default: | 61 default: |
| 61 Expect.fail("Unknown test mode"); | 62 Expect.fail("Unknown test mode"); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 class SocketCloseServer { | 213 class SocketCloseServer { |
| 213 | 214 |
| 214 static const HOST = "127.0.0.1"; | 215 static const HOST = "127.0.0.1"; |
| 215 | 216 |
| 216 SocketCloseServer() : super() {} | 217 SocketCloseServer() : super() {} |
| 217 | 218 |
| 218 void connectionHandler(ConnectionData data) { | 219 void connectionHandler(ConnectionData data) { |
| 219 var connection = data.connection; | 220 var connection = data.connection; |
| 220 | 221 |
| 221 void readBytes(whenFiveBytes) { | 222 void readBytes(whenFiveBytes) { |
| 222 List<int> b = new List<int>(5); | 223 List<int> b = new List<int>.fixedLength(5); |
| 223 data.readBytes += connection.readList(b, 0, 5); | 224 data.readBytes += connection.readList(b, 0, 5); |
| 224 if (data.readBytes == 5) { | 225 if (data.readBytes == 5) { |
| 225 whenFiveBytes(); | 226 whenFiveBytes(); |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 | 229 |
| 229 void writeHello() { | 230 void writeHello() { |
| 230 int bytesWritten = 0; | 231 int bytesWritten = 0; |
| 231 while (bytesWritten != 5) { | 232 while (bytesWritten != 5) { |
| 232 bytesWritten += connection.writeList("Hello".charCodes, | 233 bytesWritten += connection.writeList("Hello".charCodes, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 var tests = 7; | 381 var tests = 7; |
| 381 var port = new ReceivePort(); | 382 var port = new ReceivePort(); |
| 382 var completed = 0; | 383 var completed = 0; |
| 383 port.receive((message, ignore) { | 384 port.receive((message, ignore) { |
| 384 if (++completed == tests) port.close(); | 385 if (++completed == tests) port.close(); |
| 385 }); | 386 }); |
| 386 for (var i = 0; i < tests; i++) { | 387 for (var i = 0; i < tests; i++) { |
| 387 new SocketClose.start(i, port.toSendPort()); | 388 new SocketClose.start(i, port.toSendPort()); |
| 388 } | 389 } |
| 389 } | 390 } |
| OLD | NEW |