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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
11 import "dart:async"; | 11 import "dart:async"; |
12 import "dart:io"; | 12 import "dart:io"; |
13 import "dart:isolate"; | 13 import "dart:isolate"; |
| 14 |
14 const SERVER_ADDRESS = "127.0.0.1"; | 15 const SERVER_ADDRESS = "127.0.0.1"; |
15 | 16 |
16 void testWriteDestroyServer() { | 17 void testWriteDestroyServer() { |
17 int WROTE = 100000; | 18 int WROTE = 100000; |
18 RawServerSocket.bind(SERVER_ADDRESS, 0).then((server) { | 19 RawServerSocket.bind(SERVER_ADDRESS, 0).then((server) { |
19 server.listen((socket) { | 20 server.listen((socket) { |
20 socket.writeEventsEnabled = false; | 21 socket.writeEventsEnabled = false; |
21 | 22 |
22 var buffer = new List.filled(WROTE, 0); | 23 var buffer = new List.filled(WROTE, 0); |
23 int offset = 0; | 24 int offset = 0; |
24 void write() { | 25 void write() { |
25 int n = socket.write(buffer, offset, buffer.length - offset); | 26 int n = socket.write(buffer, offset, buffer.length - offset); |
26 offset += n; | 27 offset += n; |
27 socket.writeEventsEnabled = true; | 28 socket.writeEventsEnabled = true; |
28 } | 29 } |
| 30 |
29 socket.listen((e) { | 31 socket.listen((e) { |
30 if (e == RawSocketEvent.WRITE) { | 32 if (e == RawSocketEvent.WRITE) { |
31 if (offset == buffer.length) { | 33 if (offset == buffer.length) { |
32 socket.close(); | 34 socket.close(); |
33 } else { | 35 } else { |
34 write(); | 36 write(); |
35 } | 37 } |
36 } | 38 } |
37 }); | 39 }); |
38 write(); | 40 write(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 RawSocket.connect(SERVER_ADDRESS, server.port).then((socket) { | 72 RawSocket.connect(SERVER_ADDRESS, server.port).then((socket) { |
71 socket.writeEventsEnabled = false; | 73 socket.writeEventsEnabled = false; |
72 | 74 |
73 var buffer = new List.filled(WROTE, 0); | 75 var buffer = new List.filled(WROTE, 0); |
74 int offset = 0; | 76 int offset = 0; |
75 void write() { | 77 void write() { |
76 int n = socket.write(buffer, offset, buffer.length - offset); | 78 int n = socket.write(buffer, offset, buffer.length - offset); |
77 offset += n; | 79 offset += n; |
78 socket.writeEventsEnabled = true; | 80 socket.writeEventsEnabled = true; |
79 } | 81 } |
| 82 |
80 socket.listen((e) { | 83 socket.listen((e) { |
81 if (e == RawSocketEvent.WRITE) { | 84 if (e == RawSocketEvent.WRITE) { |
82 if (offset == buffer.length) { | 85 if (offset == buffer.length) { |
83 socket.close(); | 86 socket.close(); |
84 } else { | 87 } else { |
85 write(); | 88 write(); |
86 } | 89 } |
87 } | 90 } |
88 }); | 91 }); |
89 write(); | 92 write(); |
90 }); | 93 }); |
91 }); | 94 }); |
92 } | 95 } |
93 | 96 |
94 void main() { | 97 void main() { |
95 testWriteDestroyServer(); | 98 testWriteDestroyServer(); |
96 testWriteDestroyClient(); | 99 testWriteDestroyClient(); |
97 } | 100 } |
OLD | NEW |