| 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 to test socket streams. | 5 // Echo server test program to test socket streams. |
| 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 #import("dart:io"); | 12 #import("dart:io"); |
| 13 #import("dart:isolate"); | 13 #import("dart:isolate"); |
| 14 #source("testing_server.dart"); | 14 #source("testing_server.dart"); |
| 15 | 15 |
| 16 class EchoServerGame { | 16 class EchoServerGame { |
| 17 | 17 |
| 18 static final MSGSIZE = 10; | 18 static const MSGSIZE = 10; |
| 19 static final MESSAGES = 100; | 19 static const MESSAGES = 100; |
| 20 static final FIRSTCHAR = 65; | 20 static const FIRSTCHAR = 65; |
| 21 | 21 |
| 22 EchoServerGame.start() | 22 EchoServerGame.start() |
| 23 : _receivePort = new ReceivePort(), | 23 : _receivePort = new ReceivePort(), |
| 24 _sendPort = null, | 24 _sendPort = null, |
| 25 _buffer = new List<int>(MSGSIZE), | 25 _buffer = new List<int>(MSGSIZE), |
| 26 _messages = 0 { | 26 _messages = 0 { |
| 27 for (int i = 0; i < MSGSIZE; i++) { | 27 for (int i = 0; i < MSGSIZE; i++) { |
| 28 _buffer[i] = FIRSTCHAR + i; | 28 _buffer[i] = FIRSTCHAR + i; |
| 29 } | 29 } |
| 30 _sendPort = spawnFunction(startEchoServer); | 30 _sendPort = spawnFunction(startEchoServer); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 | 135 |
| 136 void startEchoServer() { | 136 void startEchoServer() { |
| 137 var server = new EchoServer(); | 137 var server = new EchoServer(); |
| 138 port.receive(server.dispatch); | 138 port.receive(server.dispatch); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 class EchoServer extends TestingServer { | 142 class EchoServer extends TestingServer { |
| 143 | 143 |
| 144 static final int MSGSIZE = EchoServerGame.MSGSIZE; | 144 static const int MSGSIZE = EchoServerGame.MSGSIZE; |
| 145 | 145 |
| 146 void onConnection(Socket connection) { | 146 void onConnection(Socket connection) { |
| 147 InputStream inputStream; | 147 InputStream inputStream; |
| 148 List<int> buffer = new List<int>(MSGSIZE); | 148 List<int> buffer = new List<int>(MSGSIZE); |
| 149 int offset = 0; | 149 int offset = 0; |
| 150 | 150 |
| 151 void dataReceived() { | 151 void dataReceived() { |
| 152 SocketOutputStream outputStream; | 152 SocketOutputStream outputStream; |
| 153 int bytesRead; | 153 int bytesRead; |
| 154 outputStream = connection.outputStream; | 154 outputStream = connection.outputStream; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 171 | 171 |
| 172 inputStream = connection.inputStream; | 172 inputStream = connection.inputStream; |
| 173 inputStream.onData = dataReceived; | 173 inputStream.onData = dataReceived; |
| 174 connection.onError = errorHandler; | 174 connection.onError = errorHandler; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 main() { | 178 main() { |
| 179 EchoServerGame echoServerGame = new EchoServerGame.start(); | 179 EchoServerGame echoServerGame = new EchoServerGame.start(); |
| 180 } | 180 } |
| OLD | NEW |