| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // | |
| 5 // Regression test for http://code.google.com/p/dart/issues/detail?id=1925. | |
| 6 // | |
| 7 // VMOptions= | |
| 8 // VMOptions=--short_socket_read | |
| 9 // VMOptions=--short_socket_write | |
| 10 // VMOptions=--short_socket_read --short_socket_write | |
| 11 | |
| 12 #import("dart:io"); | |
| 13 #import("dart:isolate"); | |
| 14 #source("TestingServer.dart"); | |
| 15 | |
| 16 final CONNECTIONS = 200; | |
| 17 | |
| 18 class Regress1925TestServer extends TestingServer { | |
| 19 | |
| 20 void onConnection(Socket socket) { | |
| 21 socket.onError = () => Expect.fail("Server socket error"); | |
| 22 socket.inputStream.onClosed = () => socket.outputStream.close(); | |
| 23 socket.inputStream.onData = () { | |
| 24 var buffer = new List(1); | |
| 25 var read = socket.inputStream.readInto(buffer); | |
| 26 Expect.equals(1, read); | |
| 27 socket.outputStream.writeFrom(buffer, 0, read); | |
| 28 }; | |
| 29 } | |
| 30 | |
| 31 int _connections = 0; | |
| 32 } | |
| 33 | |
| 34 | |
| 35 class Regress1925Test extends TestingServerTest { | |
| 36 Regress1925Test.start() : super.start(new Regress1925TestServer()); | |
| 37 | |
| 38 void run() { | |
| 39 | |
| 40 void onConnect() { | |
| 41 _connections++; | |
| 42 if (_connections == CONNECTIONS) { | |
| 43 for (int i = 0; i < CONNECTIONS; i++) { | |
| 44 _sockets[i].close(); | |
| 45 } | |
| 46 shutdown(); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 var count = 0; | |
| 51 var buffer = new List(5); | |
| 52 Socket socket = new Socket(TestingServer.HOST, _port); | |
| 53 socket.onConnect = () { | |
| 54 socket.outputStream.write("12345".charCodes()); | |
| 55 socket.outputStream.close(); | |
| 56 socket.inputStream.onData = () { | |
| 57 count += socket.inputStream.readInto(buffer, count); | |
| 58 }; | |
| 59 socket.inputStream.onClosed = () { | |
| 60 Expect.equals(5, count); | |
| 61 shutdown(); | |
| 62 }; | |
| 63 socket.inputStream.onError = () => Expect.fail("Socket error"); | |
| 64 }; | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 main() { | |
| 69 Regress1925Test test = new Regress1925Test.start(); | |
| 70 } | |
| OLD | NEW |