| 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:io"; | 10 import "dart:io"; |
| 11 import "dart:uri"; | 11 import "dart:uri"; |
| 12 | 12 |
| 13 void main() { | 13 void main() { |
| 14 final int REQUEST_COUNT = 100; | 14 final int REQUEST_COUNT = 100; |
| 15 int count = 0; | 15 int count = 0; |
| 16 HttpServer.bind().then((server) { | 16 HttpServer.bind().then((server) { |
| 17 server.listen((HttpRequest request) { | 17 server.listen((HttpRequest request) { |
| 18 count++; | 18 count++; |
| 19 request.response.addString(request.uri.path); | 19 request.response.write(request.uri.path); |
| 20 request.response.close(); | 20 request.response.close(); |
| 21 if (request.uri.path == "/done") { | 21 if (request.uri.path == "/done") { |
| 22 request.response.done.then((_) { | 22 request.response.done.then((_) { |
| 23 Expect.equals(REQUEST_COUNT + 1, count); | 23 Expect.equals(REQUEST_COUNT + 1, count); |
| 24 server.close(); | 24 server.close(); |
| 25 }); | 25 }); |
| 26 } | 26 } |
| 27 }); | 27 }); |
| 28 Socket.connect("127.0.0.1", server.port).then((s) { | 28 Socket.connect("127.0.0.1", server.port).then((s) { |
| 29 s.listen((data) { }); | 29 s.listen((data) { }); |
| 30 for (int i = 0; i < REQUEST_COUNT; i++) { | 30 for (int i = 0; i < REQUEST_COUNT; i++) { |
| 31 s.addString("GET /$i HTTP/1.1\r\nX-Header-1: 111\r\n\r\n"); | 31 s.write("GET /$i HTTP/1.1\r\nX-Header-1: 111\r\n\r\n"); |
| 32 } | 32 } |
| 33 s.addString("GET /done HTTP/1.1\r\nConnection: close\r\n\r\n"); | 33 s.write("GET /done HTTP/1.1\r\nConnection: close\r\n\r\n"); |
| 34 s.close(); | 34 s.close(); |
| 35 }); | 35 }); |
| 36 }); | 36 }); |
| 37 } | 37 } |
| OLD | NEW |