| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (_messages % 2 == 0) data = new List<int>(MSGSIZE); | 89 if (_messages % 2 == 0) data = new List<int>(MSGSIZE); |
| 90 inputStream.dataHandler = dataReceived; | 90 inputStream.dataHandler = dataReceived; |
| 91 } | 91 } |
| 92 | 92 |
| 93 _socket.setCloseHandler(closeHandler); | 93 _socket.setCloseHandler(closeHandler); |
| 94 _socket.setErrorHandler(errorHandler); | 94 _socket.setErrorHandler(errorHandler); |
| 95 bool written = stream.write(_buffer, 0, MSGSIZE, dataSent); | 95 stream.write(_buffer); |
| 96 if (written) { | 96 dataSent(); |
| 97 dataSent(); | |
| 98 } | |
| 99 } | 97 } |
| 100 | 98 |
| 101 _socket = new Socket(EchoServer.HOST, _port); | 99 _socket = new Socket(EchoServer.HOST, _port); |
| 102 if (_socket !== null) { | 100 if (_socket !== null) { |
| 103 _socket.setConnectHandler(connectHandler); | 101 _socket.setConnectHandler(connectHandler); |
| 104 } else { | 102 } else { |
| 105 Expect.fail("socket creation failed"); | 103 Expect.fail("socket creation failed"); |
| 106 } | 104 } |
| 107 } | 105 } |
| 108 | 106 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 140 |
| 143 void dataReceived() { | 141 void dataReceived() { |
| 144 SocketOutputStream outputStream = _client.outputStream; | 142 SocketOutputStream outputStream = _client.outputStream; |
| 145 int bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset); | 143 int bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset); |
| 146 if (bytesRead > 0) { | 144 if (bytesRead > 0) { |
| 147 offset += bytesRead; | 145 offset += bytesRead; |
| 148 for (int i = 0; i < offset; i++) { | 146 for (int i = 0; i < offset; i++) { |
| 149 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); | 147 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); |
| 150 } | 148 } |
| 151 if (offset == MSGSIZE) { | 149 if (offset == MSGSIZE) { |
| 152 outputStream.write(buffer, 0, buffer.length, null); | 150 outputStream.write(buffer); |
| 153 } | 151 } |
| 154 } | 152 } |
| 155 } | 153 } |
| 156 | 154 |
| 157 void closeHandler() { | 155 void closeHandler() { |
| 158 _client.close(); | 156 _client.close(); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void errorHandler() { | 159 void errorHandler() { |
| 162 print("Socket error"); | 160 print("Socket error"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 188 } | 186 } |
| 189 }); | 187 }); |
| 190 } | 188 } |
| 191 | 189 |
| 192 ServerSocket _server; | 190 ServerSocket _server; |
| 193 } | 191 } |
| 194 | 192 |
| 195 main() { | 193 main() { |
| 196 EchoServerStreamTest.testMain(); | 194 EchoServerStreamTest.testMain(); |
| 197 } | 195 } |
| OLD | NEW |