| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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); |
| 31 start(); | 31 initialize(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void sendData() { | 34 void sendData() { |
| 35 | 35 |
| 36 void errorHandler(Exception e) { | 36 void errorHandler(Exception e) { |
| 37 Expect.fail("Socket error $e"); | 37 Expect.fail("Socket error $e"); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void connectHandler() { | 40 void connectHandler() { |
| 41 | 41 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 | 105 |
| 106 _socket = new Socket(TestingServer.HOST, _port); | 106 _socket = new Socket(TestingServer.HOST, _port); |
| 107 if (_socket !== null) { | 107 if (_socket !== null) { |
| 108 _socket.onConnect = connectHandler; | 108 _socket.onConnect = connectHandler; |
| 109 } else { | 109 } else { |
| 110 Expect.fail("socket creation failed"); | 110 Expect.fail("socket creation failed"); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void start() { | 114 void initialize() { |
| 115 _receivePort.receive((var message, SendPort replyTo) { | 115 _receivePort.receive((var message, SendPort replyTo) { |
| 116 _port = message; | 116 _port = message; |
| 117 sendData(); | 117 sendData(); |
| 118 }); | 118 }); |
| 119 _sendPort.send(TestingServer.INIT, _receivePort.toSendPort()); | 119 _sendPort.send(TestingServer.INIT, _receivePort.toSendPort()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void shutdown() { | 122 void shutdown() { |
| 123 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); | 123 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); |
| 124 _receivePort.close(); | 124 _receivePort.close(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |