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"; |
11 import "dart:io"; | 11 import "dart:io"; |
12 import "dart:isolate"; | 12 import "dart:isolate"; |
13 const SERVER_ADDRESS = "127.0.0.1"; | 13 const SERVER_ADDRESS = "127.0.0.1"; |
14 | 14 |
15 void testWriteDestroyServer() { | 15 void testWriteDestroyServer() { |
16 int WROTE = 100000; | 16 int WROTE = 100000; |
17 RawServerSocket.bind(SERVER_ADDRESS).then((server) { | 17 RawServerSocket.bind(SERVER_ADDRESS).then((server) { |
18 server.listen((socket) { | 18 server.listen((socket) { |
19 socket.writeEventsEnabled = false; | 19 socket.writeEventsEnabled = false; |
20 | 20 |
21 var buffer = new List.fixedLength(WROTE, fill: 0); | 21 var buffer = new List.filled(WROTE, 0); |
22 int offset = 0; | 22 int offset = 0; |
23 void write() { | 23 void write() { |
24 int n = socket.write(buffer, offset, buffer.length - offset); | 24 int n = socket.write(buffer, offset, buffer.length - offset); |
25 offset += n; | 25 offset += n; |
26 socket.writeEventsEnabled = true; | 26 socket.writeEventsEnabled = true; |
27 } | 27 } |
28 socket.listen((e) { | 28 socket.listen((e) { |
29 if (e == RawSocketEvent.WRITE) { | 29 if (e == RawSocketEvent.WRITE) { |
30 if (offset == buffer.length) { | 30 if (offset == buffer.length) { |
31 socket.close(); | 31 socket.close(); |
(...skipping 30 matching lines...) Expand all Loading... |
62 } else if (e == RawSocketEvent.READ_CLOSED) { | 62 } else if (e == RawSocketEvent.READ_CLOSED) { |
63 Expect.equals(WROTE, bytes); | 63 Expect.equals(WROTE, bytes); |
64 socket.close(); | 64 socket.close(); |
65 server.close(); | 65 server.close(); |
66 } | 66 } |
67 }); | 67 }); |
68 }); | 68 }); |
69 RawSocket.connect(SERVER_ADDRESS, server.port).then((socket) { | 69 RawSocket.connect(SERVER_ADDRESS, server.port).then((socket) { |
70 socket.writeEventsEnabled = false; | 70 socket.writeEventsEnabled = false; |
71 | 71 |
72 var buffer = new List.fixedLength(WROTE, fill: 0); | 72 var buffer = new List.filled(WROTE, 0); |
73 int offset = 0; | 73 int offset = 0; |
74 void write() { | 74 void write() { |
75 int n = socket.write(buffer, offset, buffer.length - offset); | 75 int n = socket.write(buffer, offset, buffer.length - offset); |
76 offset += n; | 76 offset += n; |
77 socket.writeEventsEnabled = true; | 77 socket.writeEventsEnabled = true; |
78 } | 78 } |
79 socket.listen((e) { | 79 socket.listen((e) { |
80 if (e == RawSocketEvent.WRITE) { | 80 if (e == RawSocketEvent.WRITE) { |
81 if (offset == buffer.length) { | 81 if (offset == buffer.length) { |
82 socket.close(); | 82 socket.close(); |
83 } else { | 83 } else { |
84 write(); | 84 write(); |
85 } | 85 } |
86 } | 86 } |
87 }); | 87 }); |
88 write(); | 88 write(); |
89 }); | 89 }); |
90 }); | 90 }); |
91 } | 91 } |
92 | 92 |
93 void main() { | 93 void main() { |
94 testWriteDestroyServer(); | 94 testWriteDestroyServer(); |
95 testWriteDestroyClient(); | 95 testWriteDestroyClient(); |
96 } | 96 } |
OLD | NEW |