| 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 // Echo server test program for testing sockets. | 5 // Echo server test program for testing sockets. |
| 6 // | 6 // |
| 7 // VMOptions= | 7 // VMOptions= |
| 8 // VMOptions=--short_socket_read | 8 // VMOptions=--short_socket_read |
| 9 // VMOptions=--short_socket_write | 9 // VMOptions=--short_socket_write |
| 10 // VMOptions=--short_socket_read --short_socket_write | 10 // VMOptions=--short_socket_read --short_socket_write |
| 11 | 11 |
| 12 #library("EchoServerTest"); | |
| 13 #import("dart:io"); | 12 #import("dart:io"); |
| 14 #import("dart:isolate"); | 13 #import("dart:isolate"); |
| 15 #source("TestingServer.dart"); | 14 #source("TestingServer.dart"); |
| 16 | 15 |
| 17 class EchoServerTest { | 16 class EchoServerTest { |
| 18 | 17 |
| 19 static void testMain() { | 18 static void testMain() { |
| 20 EchoServerGame echoServerGame = new EchoServerGame.start(); | 19 EchoServerGame echoServerGame = new EchoServerGame.start(); |
| 21 } | 20 } |
| 22 } | 21 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ReceivePort _receivePort; | 125 ReceivePort _receivePort; |
| 127 SendPort _sendPort; | 126 SendPort _sendPort; |
| 128 List<int> _buffer; | 127 List<int> _buffer; |
| 129 int _messages; | 128 int _messages; |
| 130 } | 129 } |
| 131 | 130 |
| 132 class EchoServer extends TestingServer { | 131 class EchoServer extends TestingServer { |
| 133 | 132 |
| 134 static final msgSize = EchoServerGame.MSGSIZE; | 133 static final msgSize = EchoServerGame.MSGSIZE; |
| 135 | 134 |
| 136 void connectionHandler(Socket connection) { | 135 void onConnection(Socket connection) { |
| 137 | 136 |
| 138 void messageHandler() { | 137 void messageHandler() { |
| 139 | 138 |
| 140 List<int> buffer = new List<int>(msgSize); | 139 List<int> buffer = new List<int>(msgSize); |
| 141 int bytesRead = 0; | 140 int bytesRead = 0; |
| 142 | 141 |
| 143 void handleRead() { | 142 void handleRead() { |
| 144 int read = connection.readList(buffer, bytesRead, msgSize - bytesRead); | 143 int read = connection.readList(buffer, bytesRead, msgSize - bytesRead); |
| 145 if (read > 0) { | 144 if (read > 0) { |
| 146 bytesRead += read; | 145 bytesRead += read; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 189 |
| 191 connection.onData = messageHandler; | 190 connection.onData = messageHandler; |
| 192 connection.onClosed = closeHandler; | 191 connection.onClosed = closeHandler; |
| 193 connection.onError = errorHandler; | 192 connection.onError = errorHandler; |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 | 195 |
| 197 main() { | 196 main() { |
| 198 EchoServerTest.testMain(); | 197 EchoServerTest.testMain(); |
| 199 } | 198 } |
| OLD | NEW |