Chromium Code Reviews| Index: runtime/bin/builtin.dart |
| diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart |
| index 33882c1ad8f4d11775ad85a5aeca5bea6b8e2124..40199302ea70510babcab9970ec0ab752ae59beb 100644 |
| --- a/runtime/bin/builtin.dart |
| +++ b/runtime/bin/builtin.dart |
| @@ -157,7 +157,7 @@ String _resolveUri(String base, String userString) { |
| var uri = userString.substring(_DART_EXT.length); |
| return '$_DART_EXT${baseUri.resolve(uri)}'; |
| } else { |
| - return '${baseUri.resolve(userString)}'; |
| + return baseUri.resolve(userString).toString(); |
| } |
| } |
| @@ -205,42 +205,34 @@ String _filePathFromPackageUri(Uri uri) { |
| int _numOutstandingLoadRequests = 0; |
| - |
| +var _httpClient; |
| void _httpGet(Uri uri, String libraryUri, loadCallback(List<int> data)) { |
| - var httpClient = new HttpClient(); |
| - try { |
| - httpClient.getUrl(uri) |
| - .then((HttpClientRequest request) { |
| - request.persistentConnection = false; |
| - return request.close(); |
| - }) |
| - .then((HttpClientResponse response) { |
| - // Only create a ByteBuilder if multiple chunks are received. |
| - var builder = new BytesBuilder(copy: false); |
| - response.listen( |
| - builder.add, |
| - onDone: () { |
| - if (response.statusCode != 200) { |
| - var msg = 'Failure getting $uri: ' |
| - '${response.statusCode} ${response.reasonPhrase}'; |
| - _asyncLoadError(uri.toString(), libraryUri, msg); |
| - } |
| - |
| - List<int> data = builder.takeBytes(); |
| - httpClient.close(); |
| - loadCallback(data); |
| - }, |
| - onError: (error) { |
| - _asyncLoadError(uri.toString(), libraryUri, error); |
| - }); |
| - }) |
| - .catchError((error) { |
| - _asyncLoadError(uri.toString(), libraryUri, error); |
| - }); |
| - } catch (error) { |
| - _asyncLoadError(uri.toString(), libraryUri, error); |
| + if (_httpClient == null) { |
| + _httpClient = new HttpClient()..maxConnectionsPerHost = 6; |
| } |
| + _httpClient.getUrl(uri) |
| + .then((HttpClientRequest request) => request.close()) |
| + .then((HttpClientResponse response) { |
| + // Only create a ByteBuilder if multiple chunks are received. |
|
Ivan Posva
2014/09/03 15:37:38
I am reading this comment as a TODO, correct?
Anders Johnsen
2014/09/04 08:26:28
Removing, the bytebuffer does this for us.
|
| + var builder = new BytesBuilder(copy: false); |
| + response.listen( |
| + builder.add, |
| + onDone: () { |
| + if (response.statusCode != 200) { |
| + var msg = 'Failure getting $uri: ' |
| + '${response.statusCode} ${response.reasonPhrase}'; |
| + _asyncLoadError(uri.toString(), libraryUri, msg); |
| + } |
| + loadCallback(builder.takeBytes()); |
| + }, |
| + onError: (error) { |
| + _asyncLoadError(uri.toString(), libraryUri, error); |
| + }); |
| + }) |
| + .catchError((error) { |
| + _asyncLoadError(uri.toString(), libraryUri, error); |
| + }); |
| // TODO(floitsch): remove this line. It's just here to push an event on the |
| // event loop so that we invoke the scheduled microtasks. Also remove the |
| // import of dart:async when this line is not needed anymore. |
| @@ -264,6 +256,10 @@ void _loadScript(int tag, String uri, String libraryUri, List<int> data) { |
| "${_numOutstandingLoadRequests} requests remaining"); |
| if (_numOutstandingLoadRequests == 0) { |
| _signalDoneLoading(); |
| + if (_httpClient != null) { |
|
Ivan Posva
2014/09/03 15:37:38
Can you move this code in a helper function which
Anders Johnsen
2014/09/04 08:26:28
Good catch.
|
| + _httpClient.close(); |
| + _httpClient = null; |
| + } |
| } |
| } |