Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1000)

Unified Diff: runtime/bin/vmservice/loader.dart

Issue 889443002: Service isolate rework take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/vmservice.h ('k') | runtime/bin/vmservice/resources.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/loader.dart
diff --git a/runtime/bin/vmservice/loader.dart b/runtime/bin/vmservice/loader.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6d81f0454a0da3d6f6e475c6f922ec24cdd9f37a
--- /dev/null
+++ b/runtime/bin/vmservice/loader.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of vmservice_io;
+
+var _httpClient;
+
+void _loadHttp(sendPort, uri) {
+ if (_httpClient == null) {
+ _httpClient = new HttpClient()..maxConnectionsPerHost = 6;
+ }
+ _httpClient.getUrl(uri)
+ .then((HttpClientRequest request) => request.close())
+ .then((HttpClientResponse response) {
+ var builder = new BytesBuilder(copy: false);
+ response.listen(
+ builder.add,
+ onDone: () {
+ if (response.statusCode != 200) {
+ var msg = 'Failure getting $uri: '
+ '${response.statusCode} ${response.reasonPhrase}';
+ sendPort.send(msg);
+ } else {
+ sendPort.send(builder.takeBytes());
+ }
+ },
+ onError: (e) {
+ sendPort.send(e.toString());
+ });
+ })
+ .catchError((e) {
+ sendPort.send(e.toString());
+ });
+ // It's just here to push an event on the event loop so that we invoke the
+ // scheduled microtasks.
+ Timer.run(() {});
+}
+
+void _loadFile(sendPort, path) {
+ var sourceFile = new File(path);
+ sourceFile.readAsBytes().then((data) {
+ sendPort.send(data);
+ },
+ onError: (e) {
+ sendPort.send(e.toString());
+ });
+}
+
+_processLoadRequest(request) {
+ var sp = request[0];
+ var uri = Uri.parse(request[1]);
+ if (uri.scheme == 'file') {
+ _loadFile(sp, uri.toFilePath());
+ } else if ((uri.scheme == 'http') || (uri.scheme == 'https')) {
+ _loadHttp(sp, uri);
+ } else {
+ sp.send('Unknown scheme for $uri');
+ }
+}
« no previous file with comments | « runtime/bin/vmservice.h ('k') | runtime/bin/vmservice/resources.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698