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 // 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 // Test socket close events. | 10 // Test socket close events. |
(...skipping 15 matching lines...) Expand all Loading... |
26 _dataEvents = 0, | 26 _dataEvents = 0, |
27 _closeEvents = 0, | 27 _closeEvents = 0, |
28 _errorEvents = 0, | 28 _errorEvents = 0, |
29 _iterations = 0 { | 29 _iterations = 0 { |
30 _sendPort = spawnFunction(startSocketCloseServer); | 30 _sendPort = spawnFunction(startSocketCloseServer); |
31 initialize(); | 31 initialize(); |
32 } | 32 } |
33 | 33 |
34 void proceed() { | 34 void proceed() { |
35 if (_iterations < ITERATIONS) { | 35 if (_iterations < ITERATIONS) { |
36 new Timer(0, sendData); | 36 Timer.run(sendData); |
37 } else { | 37 } else { |
38 shutdown(); | 38 shutdown(); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 void sendData(Timer timer) { | 42 void sendData() { |
43 | 43 |
44 void dataHandler() { | 44 void dataHandler() { |
45 switch (_mode) { | 45 switch (_mode) { |
46 case 0: | 46 case 0: |
47 case 1: | 47 case 1: |
48 case 2: | 48 case 2: |
49 Expect.fail("No data expected"); | 49 Expect.fail("No data expected"); |
50 break; | 50 break; |
51 case 3: | 51 case 3: |
52 case 4: | 52 case 4: |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 289 |
290 connection.onData = dataHandler; | 290 connection.onData = dataHandler; |
291 connection.onClosed = closeHandler; | 291 connection.onClosed = closeHandler; |
292 connection.onError = errorHandler; | 292 connection.onError = errorHandler; |
293 } | 293 } |
294 | 294 |
295 void errorHandlerServer(Exception e) { | 295 void errorHandlerServer(Exception e) { |
296 Expect.fail("Server socket error"); | 296 Expect.fail("Server socket error"); |
297 } | 297 } |
298 | 298 |
299 waitForResult(Timer timer) { | 299 waitForResult() { |
300 // Make sure all iterations have been run. In multiple of these | 300 // Make sure all iterations have been run. In multiple of these |
301 // scenarios it is possible to get the SERVERSHUTDOWN message | 301 // scenarios it is possible to get the SERVERSHUTDOWN message |
302 // before we have received the last close event on the | 302 // before we have received the last close event on the |
303 // server. In these cases we wait for the correct number of | 303 // server. In these cases we wait for the correct number of |
304 // close events. | 304 // close events. |
305 if (_iterations == ITERATIONS && | 305 if (_iterations == ITERATIONS && |
306 (_closeEvents == ITERATIONS || (_mode == 2 || _mode == 3))) { | 306 (_closeEvents == ITERATIONS || (_mode == 2 || _mode == 3))) { |
307 switch (_mode) { | 307 switch (_mode) { |
308 case 0: | 308 case 0: |
309 Expect.equals(0, _dataEvents); | 309 Expect.equals(0, _dataEvents); |
(...skipping 15 matching lines...) Expand all Loading... |
325 Expect.equals(ITERATIONS, _closeEvents); | 325 Expect.equals(ITERATIONS, _closeEvents); |
326 break; | 326 break; |
327 default: | 327 default: |
328 Expect.fail("Unknown test mode"); | 328 Expect.fail("Unknown test mode"); |
329 } | 329 } |
330 Expect.equals(0, _errorEvents); | 330 Expect.equals(0, _errorEvents); |
331 _server.close(); | 331 _server.close(); |
332 port.close(); | 332 port.close(); |
333 _donePort.send(null); | 333 _donePort.send(null); |
334 } else { | 334 } else { |
335 new Timer(100, waitForResult); | 335 new Timer(new Duration(milliseconds: 100), waitForResult); |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
339 void dispatch(message, SendPort replyTo) { | 339 void dispatch(message, SendPort replyTo) { |
340 _donePort = replyTo; | 340 _donePort = replyTo; |
341 if (message != SERVERSHUTDOWN) { | 341 if (message != SERVERSHUTDOWN) { |
342 _readBytes = 0; | 342 _readBytes = 0; |
343 _errorEvents = 0; | 343 _errorEvents = 0; |
344 _dataEvents = 0; | 344 _dataEvents = 0; |
345 _closeEvents = 0; | 345 _closeEvents = 0; |
346 _iterations = 0; | 346 _iterations = 0; |
347 _mode = message; | 347 _mode = message; |
348 _server = new ServerSocket(HOST, 0, 10); | 348 _server = new ServerSocket(HOST, 0, 10); |
349 Expect.equals(true, _server != null); | 349 Expect.equals(true, _server != null); |
350 _server.onConnection = (connection) { | 350 _server.onConnection = (connection) { |
351 var data = new ConnectionData(connection); | 351 var data = new ConnectionData(connection); |
352 connectionHandler(data); | 352 connectionHandler(data); |
353 }; | 353 }; |
354 _server.onError = errorHandlerServer; | 354 _server.onError = errorHandlerServer; |
355 replyTo.send(_server.port, null); | 355 replyTo.send(_server.port, null); |
356 } else { | 356 } else { |
357 new Timer(0, waitForResult); | 357 Timer.run(waitForResult); |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 ServerSocket _server; | 361 ServerSocket _server; |
362 SendPort _donePort; | 362 SendPort _donePort; |
363 int _readBytes; | 363 int _readBytes; |
364 int _errorEvents; | 364 int _errorEvents; |
365 int _dataEvents; | 365 int _dataEvents; |
366 int _closeEvents; | 366 int _closeEvents; |
367 int _iterations; | 367 int _iterations; |
(...skipping 13 matching lines...) Expand all Loading... |
381 var tests = 7; | 381 var tests = 7; |
382 var port = new ReceivePort(); | 382 var port = new ReceivePort(); |
383 var completed = 0; | 383 var completed = 0; |
384 port.receive((message, ignore) { | 384 port.receive((message, ignore) { |
385 if (++completed == tests) port.close(); | 385 if (++completed == tests) port.close(); |
386 }); | 386 }); |
387 for (var i = 0; i < tests; i++) { | 387 for (var i = 0; i < tests; i++) { |
388 new SocketClose.start(i, port.toSendPort()); | 388 new SocketClose.start(i, port.toSendPort()); |
389 } | 389 } |
390 } | 390 } |
OLD | NEW |