| 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 21 matching lines...) Expand all Loading... |
| 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 |
| 42 SocketOutputStream stream = _socket.outputStream; | 42 OutputStream stream = _socket.outputStream; |
| 43 | 43 |
| 44 void dataSent() { | 44 void dataSent() { |
| 45 InputStream inputStream = _socket.inputStream; | 45 InputStream inputStream = _socket.inputStream; |
| 46 int offset = 0; | 46 int offset = 0; |
| 47 List<int> data; | 47 List<int> data; |
| 48 | 48 |
| 49 void onClosed() { | 49 void onClosed() { |
| 50 Expect.equals(MSGSIZE, offset); | 50 Expect.equals(MSGSIZE, offset); |
| 51 _messages++; | 51 _messages++; |
| 52 if (_messages < MESSAGES) { | 52 if (_messages < MESSAGES) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 class EchoServer extends TestingServer { | 142 class EchoServer extends TestingServer { |
| 143 | 143 |
| 144 static const 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; | |
| 153 int bytesRead; | 152 int bytesRead; |
| 154 outputStream = connection.outputStream; | 153 OutputStream outputStream = connection.outputStream; |
| 155 bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset); | 154 bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset); |
| 156 if (bytesRead > 0) { | 155 if (bytesRead > 0) { |
| 157 offset += bytesRead; | 156 offset += bytesRead; |
| 158 for (int i = 0; i < offset; i++) { | 157 for (int i = 0; i < offset; i++) { |
| 159 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); | 158 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); |
| 160 } | 159 } |
| 161 if (offset == MSGSIZE) { | 160 if (offset == MSGSIZE) { |
| 162 outputStream.write(buffer); | 161 outputStream.write(buffer); |
| 163 outputStream.close(); | 162 outputStream.close(); |
| 164 } | 163 } |
| 165 } | 164 } |
| 166 } | 165 } |
| 167 | 166 |
| 168 void errorHandler(Exception e) { | 167 void errorHandler(Exception e) { |
| 169 Expect.fail("Socket error $e"); | 168 Expect.fail("Socket error $e"); |
| 170 } | 169 } |
| 171 | 170 |
| 172 inputStream = connection.inputStream; | 171 inputStream = connection.inputStream; |
| 173 inputStream.onData = dataReceived; | 172 inputStream.onData = dataReceived; |
| 174 connection.onError = errorHandler; | 173 connection.onError = errorHandler; |
| 175 } | 174 } |
| 176 } | 175 } |
| 177 | 176 |
| 178 main() { | 177 main() { |
| 179 EchoServerGame echoServerGame = new EchoServerGame.start(); | 178 EchoServerGame echoServerGame = new EchoServerGame.start(); |
| 180 } | 179 } |
| OLD | NEW |