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 |
15 main() { | 15 main() { |
16 HttpServer.bind("127.0.0.1", 0).then((server) { | 16 HttpServer.bind("127.0.0.1", 0).then((server) { |
17 server.listen( | 17 server.listen((request) { |
18 (request) { | 18 String name = Platform.script.toFilePath(); |
19 String name = Platform.script.toFilePath(); | 19 new File(name) |
20 new File(name).openRead().pipe(request.response) | 20 .openRead() |
21 .catchError((e) { /* ignore */ }); | 21 .pipe(request.response) |
22 }); | 22 .catchError((e) {/* ignore */}); |
| 23 }); |
23 | 24 |
24 var count = 0; | 25 var count = 0; |
25 makeRequest() { | 26 makeRequest() { |
26 Socket.connect("127.0.0.1", server.port).then((socket) { | 27 Socket.connect("127.0.0.1", server.port).then((socket) { |
27 var data = "GET / HTTP/1.1\r\nContent-Length: 0\r\n\r\n"; | 28 var data = "GET / HTTP/1.1\r\nContent-Length: 0\r\n\r\n"; |
28 socket.write(data); | 29 socket.write(data); |
29 socket.close(); | 30 socket.close(); |
30 socket.done.then((_) { | 31 socket.done.then((_) { |
31 socket.destroy(); | 32 socket.destroy(); |
32 if (++count < 10) { | 33 if (++count < 10) { |
33 makeRequest(); | 34 makeRequest(); |
34 } else { | 35 } else { |
35 server.close(); | 36 server.close(); |
36 } | 37 } |
37 }); | 38 }); |
38 }); | 39 }); |
39 } | 40 } |
| 41 |
40 makeRequest(); | 42 makeRequest(); |
41 }); | 43 }); |
42 } | 44 } |
OLD | NEW |