OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import "dart:async"; | 10 import "dart:async"; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 void testSimpleReadWrite() { | 130 void testSimpleReadWrite() { |
131 // This test creates a server and a client connects. The client then | 131 // This test creates a server and a client connects. The client then |
132 // writes and the server echos. When the server has finished its | 132 // writes and the server echos. When the server has finished its |
133 // echo it half-closes. When the client gets the close event is | 133 // echo it half-closes. When the client gets the close event is |
134 // closes fully. | 134 // closes fully. |
135 ReceivePort port = new ReceivePort(); | 135 ReceivePort port = new ReceivePort(); |
136 | 136 |
137 const messageSize = 1000; | 137 const messageSize = 1000; |
138 | 138 |
139 List<int> createTestData() { | 139 List<int> createTestData() { |
140 List<int> data = new List.fixedLength(messageSize); | 140 List<int> data = new List<int>(messageSize); |
141 for (int i = 0; i < messageSize; i++) { | 141 for (int i = 0; i < messageSize; i++) { |
142 data[i] = i & 0xff; | 142 data[i] = i & 0xff; |
143 } | 143 } |
144 return data; | 144 return data; |
145 } | 145 } |
146 | 146 |
147 void verifyTestData(List<int> data) { | 147 void verifyTestData(List<int> data) { |
148 Expect.equals(messageSize, data.length); | 148 Expect.equals(messageSize, data.length); |
149 List<int> expected = createTestData(); | 149 List<int> expected = createTestData(); |
150 for (int i = 0; i < messageSize; i++) { | 150 for (int i = 0; i < messageSize; i++) { |
151 Expect.equals(expected[i], data[i]); | 151 Expect.equals(expected[i], data[i]); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 RawServerSocket.bind().then((server) { | 155 RawServerSocket.bind().then((server) { |
156 server.listen((client) { | 156 server.listen((client) { |
157 int bytesRead = 0; | 157 int bytesRead = 0; |
158 int bytesWritten = 0; | 158 int bytesWritten = 0; |
159 List<int> data = new List.fixedLength(messageSize); | 159 List<int> data = new List<int>(messageSize); |
160 | 160 |
161 client.writeEventsEnabled = false; | 161 client.writeEventsEnabled = false; |
162 client.listen((event) { | 162 client.listen((event) { |
163 switch (event) { | 163 switch (event) { |
164 case RawSocketEvent.READ: | 164 case RawSocketEvent.READ: |
165 Expect.isTrue(bytesWritten == 0); | 165 Expect.isTrue(bytesWritten == 0); |
166 Expect.isTrue(client.available() > 0); | 166 Expect.isTrue(client.available() > 0); |
167 var buffer = client.read(); | 167 var buffer = client.read(); |
168 data.setRange(bytesRead, buffer.length, buffer); | 168 data.setRange(bytesRead, buffer.length, buffer); |
169 bytesRead += buffer.length; | 169 bytesRead += buffer.length; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 bytesRead += buffer.length; | 205 bytesRead += buffer.length; |
206 break; | 206 break; |
207 case RawSocketEvent.WRITE: | 207 case RawSocketEvent.WRITE: |
208 Expect.isTrue(bytesRead == 0); | 208 Expect.isTrue(bytesRead == 0); |
209 Expect.isFalse(socket.writeEventsEnabled); | 209 Expect.isFalse(socket.writeEventsEnabled); |
210 bytesWritten += socket.write( | 210 bytesWritten += socket.write( |
211 data, bytesWritten, data.length - bytesWritten); | 211 data, bytesWritten, data.length - bytesWritten); |
212 if (bytesWritten < data.length) { | 212 if (bytesWritten < data.length) { |
213 socket.writeEventsEnabled = true; | 213 socket.writeEventsEnabled = true; |
214 } else { | 214 } else { |
215 data = new List.fixedLength(messageSize); | 215 data = new List<int>(messageSize); |
216 } | 216 } |
217 break; | 217 break; |
218 case RawSocketEvent.READ_CLOSED: | 218 case RawSocketEvent.READ_CLOSED: |
219 verifyTestData(data); | 219 verifyTestData(data); |
220 socket.close(); | 220 socket.close(); |
221 break; | 221 break; |
222 default: throw "Unexpected event $event"; | 222 default: throw "Unexpected event $event"; |
223 } | 223 } |
224 }, | 224 }, |
225 onDone: () => port.close()); | 225 onDone: () => port.close()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 int bytesWritten = 0; | 325 int bytesWritten = 0; |
326 int bytesRead = 0; | 326 int bytesRead = 0; |
327 var writeSubscription; | 327 var writeSubscription; |
328 var readSubscription; | 328 var readSubscription; |
329 | 329 |
330 ReceivePort port = new ReceivePort(); | 330 ReceivePort port = new ReceivePort(); |
331 | 331 |
332 RawServerSocket.bind().then((server) { | 332 RawServerSocket.bind().then((server) { |
333 Expect.isTrue(server.port > 0); | 333 Expect.isTrue(server.port > 0); |
334 server.listen((client) { | 334 server.listen((client) { |
335 List<int> data = new List.fixedLength(messageSize, fill: 0); | 335 List<int> data = new List<int>.filled(messageSize, 0); |
336 writeSubscription = client.listen((event) { | 336 writeSubscription = client.listen((event) { |
337 switch (event) { | 337 switch (event) { |
338 case RawSocketEvent.READ: | 338 case RawSocketEvent.READ: |
339 throw "Unexpected read event"; | 339 throw "Unexpected read event"; |
340 case RawSocketEvent.WRITE: | 340 case RawSocketEvent.WRITE: |
341 if (pauseResumeCount == loopCount) return; | 341 if (pauseResumeCount == loopCount) return; |
342 Expect.isFalse(client.writeEventsEnabled); | 342 Expect.isFalse(client.writeEventsEnabled); |
343 Expect.equals(0, bytesRead); // Checks that reader is paused. | 343 Expect.equals(0, bytesRead); // Checks that reader is paused. |
344 bytesWritten += client.write( | 344 bytesWritten += client.write( |
345 data, bytesWritten, data.length - bytesWritten); | 345 data, bytesWritten, data.length - bytesWritten); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 testCloseOneEnd("client"); | 403 testCloseOneEnd("client"); |
404 testCloseOneEnd("server"); | 404 testCloseOneEnd("server"); |
405 testInvalidBind(); | 405 testInvalidBind(); |
406 testSimpleConnect(); | 406 testSimpleConnect(); |
407 testServerListenAfterConnect(); | 407 testServerListenAfterConnect(); |
408 testSimpleReadWrite(); | 408 testSimpleReadWrite(); |
409 testPauseServerSocket(); | 409 testPauseServerSocket(); |
410 testCancelResubscribeServerSocket(); | 410 testCancelResubscribeServerSocket(); |
411 testPauseSocket(); | 411 testPauseSocket(); |
412 } | 412 } |
OLD | NEW |