| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 Socket _socket; | 132 Socket _socket; |
| 133 List<int> _buffer; | 133 List<int> _buffer; |
| 134 int _messages; | 134 int _messages; |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 class EchoServer extends TestingServer { | 138 class EchoServer extends TestingServer { |
| 139 | 139 |
| 140 static final int MSGSIZE = EchoServerGame.MSGSIZE; | 140 static final int MSGSIZE = EchoServerGame.MSGSIZE; |
| 141 | 141 |
| 142 void connectionHandler() { | 142 void connectionHandler(Socket connection) { |
| 143 Socket _client; | |
| 144 InputStream inputStream; | 143 InputStream inputStream; |
| 145 List<int> buffer = new List<int>(MSGSIZE); | 144 List<int> buffer = new List<int>(MSGSIZE); |
| 146 int offset = 0; | 145 int offset = 0; |
| 147 | 146 |
| 148 void dataReceived() { | 147 void dataReceived() { |
| 149 SocketOutputStream outputStream; | 148 SocketOutputStream outputStream; |
| 150 int bytesRead; | 149 int bytesRead; |
| 151 outputStream = _client.outputStream; | 150 outputStream = connection.outputStream; |
| 152 bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset); | 151 bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset); |
| 153 if (bytesRead > 0) { | 152 if (bytesRead > 0) { |
| 154 offset += bytesRead; | 153 offset += bytesRead; |
| 155 for (int i = 0; i < offset; i++) { | 154 for (int i = 0; i < offset; i++) { |
| 156 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); | 155 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); |
| 157 } | 156 } |
| 158 if (offset == MSGSIZE) { | 157 if (offset == MSGSIZE) { |
| 159 outputStream.write(buffer); | 158 outputStream.write(buffer); |
| 160 outputStream.close(); | 159 outputStream.close(); |
| 161 } | 160 } |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 void errorHandler() { | 164 void errorHandler() { |
| 166 Expect.fail("Socket error"); | 165 Expect.fail("Socket error"); |
| 167 } | 166 } |
| 168 | 167 |
| 169 _client = _server.accept(); | 168 inputStream = connection.inputStream; |
| 170 inputStream = _client.inputStream; | |
| 171 inputStream.dataHandler = dataReceived; | 169 inputStream.dataHandler = dataReceived; |
| 172 _client.errorHandler = errorHandler; | 170 connection.errorHandler = errorHandler; |
| 173 } | 171 } |
| 174 } | 172 } |
| 175 | 173 |
| 176 main() { | 174 main() { |
| 177 EchoServerGame echoServerGame = new EchoServerGame.start(); | 175 EchoServerGame echoServerGame = new EchoServerGame.start(); |
| 178 } | 176 } |
| OLD | NEW |