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

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

Issue 19622003: VM Service isolate listing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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/running_isolates.dart ('k') | runtime/bin/vmservice/service_request.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/server.dart
diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cf603f3a041a65121d2b636929271b75c728c445
--- /dev/null
+++ b/runtime/bin/vmservice/server.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2013, 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;
+
+class Server {
+ int port;
+ static ContentType jsonContentType = ContentType.parse('application/json');
+ final VmService service;
+ HttpServer _server;
+
+ Server(this.service, this.port);
+
+ void _requestHandler(HttpRequest request) {
+ // Allow cross origin requests.
+ request.response.headers.add('Access-Control-Allow-Origin', '*');
+
+ final String path =
+ request.uri.path == '/' ? '/index.html' : request.uri.path;
+
+ var resource = Resource.resources[path];
+ if (resource != null) {
+ // Serving up a static resource (e.g. .css, .html, .png).
+ request.response.headers.contentType = ContentType.parse(mimeType);
+ request.response.add(resource.data);
+ request.response.close();
+ return;
+ }
+
+ var serviceRequest = new ServiceRequest();
+ var r = serviceRequest.parse(request.uri);
+ if (!r) {
+ // Did not understand the request uri.
+ serviceRequest.setErrorResponse('Invalid request uri: ${request.uri}');
+ } else {
+ r = service.runningIsolates.route(serviceRequest);
+ if (!r) {
+ // Nothing responds to this type of request.
+ serviceRequest.setErrorResponse('No route for: $path');
+ }
+ }
+
+ // Send response back over HTTP.
+ request.response.headers.contentType = jsonContentType;
+ request.response.write(serviceRequest.response);
+ request.response.close();
+ }
+
+ Future startServer() {
+ return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((s) {
+ // Only display message when port is automatically selected.
+ var display_message = (port == 0);
+ // Retrieve port.
+ port = s.port;
+ _server = s;
+ _server.listen(_requestHandler);
+ if (display_message) {
+ print('VmService listening on port $port');
+ }
+ return s;
+ });
+ }
+}
+
« no previous file with comments | « runtime/bin/vmservice/running_isolates.dart ('k') | runtime/bin/vmservice/service_request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698