| 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:io"); |
| 13 #import("dart:isolate"); | 13 #import("dart:isolate"); |
| 14 | 14 |
| 15 final SERVERSHUTDOWN = -1; | 15 const SERVERSHUTDOWN = -1; |
| 16 final ITERATIONS = 10; | 16 const ITERATIONS = 10; |
| 17 | 17 |
| 18 | 18 |
| 19 class SocketClose { | 19 class SocketClose { |
| 20 | 20 |
| 21 SocketClose.start(this._mode, this._donePort) | 21 SocketClose.start(this._mode, this._donePort) |
| 22 : _receivePort = new ReceivePort(), | 22 : _receivePort = new ReceivePort(), |
| 23 _sendPort = null, | 23 _sendPort = null, |
| 24 _readBytes = 0, | 24 _readBytes = 0, |
| 25 _dataEvents = 0, | 25 _dataEvents = 0, |
| 26 _closeEvents = 0, | 26 _closeEvents = 0, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 | 215 |
| 216 void startSocketCloseServer() { | 216 void startSocketCloseServer() { |
| 217 var server = new SocketCloseServer(); | 217 var server = new SocketCloseServer(); |
| 218 port.receive(server.dispatch); | 218 port.receive(server.dispatch); |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 class SocketCloseServer { | 222 class SocketCloseServer { |
| 223 | 223 |
| 224 static final HOST = "127.0.0.1"; | 224 static const HOST = "127.0.0.1"; |
| 225 | 225 |
| 226 SocketCloseServer() : super() {} | 226 SocketCloseServer() : super() {} |
| 227 | 227 |
| 228 void connectionHandler(ConnectionData data) { | 228 void connectionHandler(ConnectionData data) { |
| 229 var connection = data.connection; | 229 var connection = data.connection; |
| 230 | 230 |
| 231 void readBytes(whenFiveBytes) { | 231 void readBytes(whenFiveBytes) { |
| 232 var read = connection.inputStream.read(); | 232 var read = connection.inputStream.read(); |
| 233 data.readBytes += read.length; | 233 data.readBytes += read.length; |
| 234 if (data.readBytes == 5) { | 234 if (data.readBytes == 5) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 var tests = 9; | 408 var tests = 9; |
| 409 var port = new ReceivePort(); | 409 var port = new ReceivePort(); |
| 410 var completed = 0; | 410 var completed = 0; |
| 411 port.receive((message, ignore) { | 411 port.receive((message, ignore) { |
| 412 if (++completed == tests) port.close(); | 412 if (++completed == tests) port.close(); |
| 413 }); | 413 }); |
| 414 for (var i = 0; i < tests; i++) { | 414 for (var i = 0; i < tests; i++) { |
| 415 new SocketClose.start(i, port.toSendPort()); | 415 new SocketClose.start(i, port.toSendPort()); |
| 416 } | 416 } |
| 417 } | 417 } |
| OLD | NEW |