| 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 | 5 |
| 6 import "dart:isolate"; | 6 import "dart:isolate"; |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 void test1(int totalConnections) { | 9 void test1(int totalConnections) { |
| 10 // Server which just closes immediately. | 10 // Server which just closes immediately. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 if (count == totalConnections) { | 27 if (count == totalConnections) { |
| 28 client.shutdown(); | 28 client.shutdown(); |
| 29 server.close(); | 29 server.close(); |
| 30 } | 30 } |
| 31 }; | 31 }; |
| 32 }; | 32 }; |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 void test2(int totalConnections) { | 37 void test2(int totalConnections, int outputStreamWrites) { |
| 38 // Server which responds without waiting for request body. | 38 // Server which responds without waiting for request body. |
| 39 HttpServer server = new HttpServer(); | 39 HttpServer server = new HttpServer(); |
| 40 server.listen("127.0.0.1", 0, backlog: totalConnections); | 40 server.listen("127.0.0.1", 0, backlog: totalConnections); |
| 41 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { | 41 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { |
| 42 response.outputStream.writeString("!dlrow ,olleH"); | 42 response.outputStream.writeString("!dlrow ,olleH"); |
| 43 response.outputStream.close(); | 43 response.outputStream.close(); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 int count = 0; | 46 int count = 0; |
| 47 HttpClient client = new HttpClient(); | 47 HttpClient client = new HttpClient(); |
| 48 for (int i = 0; i < totalConnections; i++) { | 48 for (int i = 0; i < totalConnections; i++) { |
| 49 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); | 49 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 50 conn.onRequest = (HttpClientRequest request) { | 50 conn.onRequest = (HttpClientRequest request) { |
| 51 request.contentLength = -1; | 51 request.contentLength = -1; |
| 52 request.outputStream.writeString("Hello, world!"); | 52 for (int i = 0; i < outputStreamWrites; i++) |
| 53 request.outputStream.writeString("Hello, world!"); |
| 53 request.outputStream.close(); | 54 request.outputStream.close(); |
| 54 }; | 55 }; |
| 55 conn.onResponse = (HttpClientResponse response) { | 56 conn.onResponse = (HttpClientResponse response) { |
| 56 response.inputStream.onData = response.inputStream.read; | 57 response.inputStream.onData = response.inputStream.read; |
| 57 response.inputStream.onClosed = () { | 58 response.inputStream.onClosed = () { |
| 58 count++; | 59 count++; |
| 59 if (count == totalConnections) { | 60 if (count == totalConnections) { |
| 60 client.shutdown(); | 61 client.shutdown(); |
| 61 server.close(); | 62 server.close(); |
| 62 } | 63 } |
| 63 }; | 64 }; |
| 64 }; | 65 }; |
| 66 conn.onError = (e) { |
| 67 count++; |
| 68 if (count == totalConnections) { |
| 69 client.shutdown(); |
| 70 server.close(); |
| 71 } |
| 72 }; |
| 65 } | 73 } |
| 66 } | 74 } |
| 67 | 75 |
| 68 | 76 |
| 69 void test3(int totalConnections) { | 77 void test3(int totalConnections) { |
| 70 // Server which responds when request body has been received. | 78 // Server which responds when request body has been received. |
| 71 HttpServer server = new HttpServer(); | 79 HttpServer server = new HttpServer(); |
| 72 server.listen("127.0.0.1", 0, backlog: totalConnections); | 80 server.listen("127.0.0.1", 0, backlog: totalConnections); |
| 73 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { | 81 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { |
| 74 request.inputStream.onData = () { | 82 request.inputStream.onData = () { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 timer.cancel(); | 169 timer.cancel(); |
| 162 } | 170 } |
| 163 } | 171 } |
| 164 }); | 172 }); |
| 165 } | 173 } |
| 166 | 174 |
| 167 | 175 |
| 168 void main() { | 176 void main() { |
| 169 test1(1); | 177 test1(1); |
| 170 test1(10); | 178 test1(10); |
| 171 test2(1); | 179 test2(1, 10); |
| 172 test2(10); | 180 test2(10, 10); |
| 181 test2(10, 1000); |
| 173 test3(1); | 182 test3(1); |
| 174 test3(10); | 183 test3(10); |
| 175 test4(); | 184 test4(); |
| 176 test5(1); | 185 test5(1); |
| 177 test5(10); | 186 test5(10); |
| 178 } | 187 } |
| OLD | NEW |