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 stream read until functionality. | 5 // Echo server test program to test socket stream read until functionality. |
| 6 // |
| 7 // VMOptions= |
| 8 // VMOptions=--short_socket_read |
| 9 // VMOptions=--short_socket_write |
| 10 // VMOptions=--short_socket_read --short_socket_write |
6 | 11 |
7 main() { | 12 main() { |
8 EchoServerStreamReadUntilTest.testMain(); | 13 EchoServerStreamReadUntilTest.testMain(); |
9 } | 14 } |
10 | 15 |
11 class EchoServerStreamReadUntilTest { | 16 class EchoServerStreamReadUntilTest { |
12 | 17 |
13 static void testMain() { | 18 static void testMain() { |
14 EchoServerGame echoServerGame = new EchoServerGame.start(); | 19 EchoServerGame echoServerGame = new EchoServerGame.start(); |
15 } | 20 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 SocketOutputStream outputStream = _client.outputStream; | 144 SocketOutputStream outputStream = _client.outputStream; |
140 | 145 |
141 // Data is expected to arrive in two chunks. First all but the | 146 // Data is expected to arrive in two chunks. First all but the |
142 // last character and second a single character. | 147 // last character and second a single character. |
143 void dataReceived(List<int> buffer) { | 148 void dataReceived(List<int> buffer) { |
144 | 149 |
145 if (buffer.length == MSGSIZE - 1) { | 150 if (buffer.length == MSGSIZE - 1) { |
146 for (int i = 0; i < MSGSIZE - 1; i++) { | 151 for (int i = 0; i < MSGSIZE - 1; i++) { |
147 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); | 152 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); |
148 } | 153 } |
149 outputStream.write(buffer, 0, buffer.length, null); | 154 void next() { |
150 inputStream.readUntil(PATTERN2, dataReceived); | 155 inputStream.readUntil(PATTERN2, dataReceived); |
| 156 } |
| 157 bool done = outputStream.write(buffer, 0, buffer.length, next); |
| 158 if (done) { |
| 159 next(); |
| 160 } |
151 } else { | 161 } else { |
152 Expect.equals(1, buffer.length); | 162 Expect.equals(1, buffer.length); |
153 outputStream.write(buffer, 0, buffer.length, null); | 163 outputStream.write(buffer, 0, buffer.length, null); |
154 inputStream.readUntil(PATTERN2, dataReceived); | |
155 } | 164 } |
156 } | 165 } |
157 | 166 |
158 void closeHandler() { | 167 void closeHandler() { |
159 _client.close(); | 168 _client.close(); |
160 } | 169 } |
161 | 170 |
162 void errorHandler() { | 171 void errorHandler() { |
163 print("Socket error"); | 172 print("Socket error"); |
164 Expect.equals(true, false); | 173 Expect.equals(true, false); |
(...skipping 27 matching lines...) Expand all Loading... |
192 replyTo.send(port, null); | 201 replyTo.send(port, null); |
193 } else if (message == EchoServerGame.SERVERSHUTDOWN) { | 202 } else if (message == EchoServerGame.SERVERSHUTDOWN) { |
194 _server.close(); | 203 _server.close(); |
195 this.port.close(); | 204 this.port.close(); |
196 } | 205 } |
197 }); | 206 }); |
198 } | 207 } |
199 | 208 |
200 ServerSocket _server; | 209 ServerSocket _server; |
201 } | 210 } |
OLD | NEW |