| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 static final FIRSTCHAR = 65; | 28 static final FIRSTCHAR = 65; |
| 29 | 29 |
| 30 EchoServerGame.start() | 30 EchoServerGame.start() |
| 31 : _receivePort = new ReceivePort(), | 31 : _receivePort = new ReceivePort(), |
| 32 _sendPort = null, | 32 _sendPort = null, |
| 33 _buffer = new List<int>(MSGSIZE), | 33 _buffer = new List<int>(MSGSIZE), |
| 34 _messages = 0 { | 34 _messages = 0 { |
| 35 for (int i = 0; i < MSGSIZE; i++) { | 35 for (int i = 0; i < MSGSIZE; i++) { |
| 36 _buffer[i] = FIRSTCHAR + i; | 36 _buffer[i] = FIRSTCHAR + i; |
| 37 } | 37 } |
| 38 new EchoServer().spawn().then((SendPort port) { | 38 _sendPort = spawnFunction(startEchoServer); |
| 39 _sendPort = port; | 39 start(); |
| 40 start(); | |
| 41 }); | |
| 42 } | 40 } |
| 43 | 41 |
| 44 void sendData() { | 42 void sendData() { |
| 45 Socket _socket; | 43 Socket _socket; |
| 46 | 44 |
| 47 void messageHandler() { | 45 void messageHandler() { |
| 48 | 46 |
| 49 List<int> bufferReceived = new List<int>(MSGSIZE); | 47 List<int> bufferReceived = new List<int>(MSGSIZE); |
| 50 int bytesRead = 0; | 48 int bytesRead = 0; |
| 51 | 49 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 _receivePort.close(); | 120 _receivePort.close(); |
| 123 } | 121 } |
| 124 | 122 |
| 125 int _port; | 123 int _port; |
| 126 ReceivePort _receivePort; | 124 ReceivePort _receivePort; |
| 127 SendPort _sendPort; | 125 SendPort _sendPort; |
| 128 List<int> _buffer; | 126 List<int> _buffer; |
| 129 int _messages; | 127 int _messages; |
| 130 } | 128 } |
| 131 | 129 |
| 130 |
| 131 void startEchoServer() { |
| 132 var server = new EchoServer(); |
| 133 port.receive(server.dispatch); |
| 134 } |
| 135 |
| 132 class EchoServer extends TestingServer { | 136 class EchoServer extends TestingServer { |
| 133 | 137 |
| 134 static final msgSize = EchoServerGame.MSGSIZE; | 138 static final msgSize = EchoServerGame.MSGSIZE; |
| 135 | 139 |
| 136 void onConnection(Socket connection) { | 140 void onConnection(Socket connection) { |
| 137 | 141 |
| 138 void messageHandler() { | 142 void messageHandler() { |
| 139 | 143 |
| 140 List<int> buffer = new List<int>(msgSize); | 144 List<int> buffer = new List<int>(msgSize); |
| 141 int bytesRead = 0; | 145 int bytesRead = 0; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 194 |
| 191 connection.onData = messageHandler; | 195 connection.onData = messageHandler; |
| 192 connection.onClosed = closeHandler; | 196 connection.onClosed = closeHandler; |
| 193 connection.onError = errorHandler; | 197 connection.onError = errorHandler; |
| 194 } | 198 } |
| 195 } | 199 } |
| 196 | 200 |
| 197 main() { | 201 main() { |
| 198 EchoServerTest.testMain(); | 202 EchoServerTest.testMain(); |
| 199 } | 203 } |
| OLD | NEW |