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

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

Issue 237113002: SIGQUIT toggles VM service HTTP server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/main.cc ('k') | runtime/bin/vmservice/vmservice_io.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
index 4d2587a2defca6c58c4736daee0fcd06853eb562..d50727fc03ab7241ea717070774b32d1f680430b 100644
--- a/runtime/bin/vmservice/server.dart
+++ b/runtime/bin/vmservice/server.dart
@@ -80,14 +80,19 @@ class HttpRequestClient extends Client {
class Server {
static const WEBSOCKET_PATH = '/ws';
- String observatoryPath = '/index.html';
- final String ip;
- int port;
+ static const ROOT_REDIRECT_PATH = '/index.html';
+
+ final VMService _service;
+ final String _ip;
+ final int _port;
- final VMService service;
HttpServer _server;
+ bool get running => _server != null;
+ bool _displayMessages = false;
- Server(this.service, this.ip, this.port);
+ Server(this._service, this._ip, this._port) {
+ _displayMessages = (_ip != '127.0.0.1' || _port != 8181);
+ }
bool _shouldServeObservatory(HttpRequest request) {
if (request.headers['Observatory-Version'] != null) {
@@ -117,18 +122,18 @@ class Server {
}
final String path =
- request.uri.path == '/' ? observatoryPath : request.uri.path;
+ request.uri.path == '/' ? ROOT_REDIRECT_PATH : request.uri.path;
if (path == WEBSOCKET_PATH) {
WebSocketTransformer.upgrade(request).then((WebSocket webSocket) {
- new WebSocketClient(webSocket, service);
+ new WebSocketClient(webSocket, _service);
});
return;
}
var resource = Resource.resources[path];
if (resource == null && _shouldServeObservatory(request)) {
- resource = Resource.resources[observatoryPath];
+ resource = Resource.resources[ROOT_REDIRECT_PATH];
assert(resource != null);
}
if (resource != null) {
@@ -140,22 +145,56 @@ class Server {
return;
}
var message = new Message.fromUri(request.uri);
- var client = new HttpRequestClient(request, service);
+ var client = new HttpRequestClient(request, _service);
client.onMessage(null, message);
}
- Future startServer() {
- return HttpServer.bind(ip, port).then((s) {
- // Only display message when port is automatically selected.
- var display_message = (ip != '127.0.0.1' || port != 8181);
- // Retrieve port.
- port = s.port;
+ Future startup() {
+ if (_server != null) {
+ // Already running.
+ return new Future.value(this);
+ }
+
+ // Startup HTTP server.
+ return HttpServer.bind(_ip, _port).then((s) {
_server = s;
_server.listen(_requestHandler);
- if (display_message) {
+ if (_displayMessages) {
+ var ip = _server.address.address.toString();
+ var port = _server.port.toString();
print('Observatory listening on http://$ip:$port');
}
- return s;
+ // Server is up and running.
+ return this;
+ }).catchError((e, st) {
+ print('Could not start Observatory HTTP server:\n$e\n$st\n');
+ return this;
+ });
+ }
+
+ Future shutdown(bool forced) {
+ if (_server == null) {
+ // Not started.
+ return new Future.value(this);
+ }
+
+ // Force displaying of status messages if we are forcibly shutdown.
+ _displayMessages = _displayMessages || forced;
+
+ // Shutdown HTTP server and subscription.
+ var ip = _server.address.address.toString();
+ var port = _server.port.toString();
+ return _server.close(force: forced).then((_) {
+ if (_displayMessages) {
+ print('Observatory no longer listening on http://$ip:$port');
+ }
+ _server = null;
+ return this;
+ }).catchError((e, st) {
+ _server = null;
+ print('Could not shutdown Observatory HTTP server:\n$e\n$st\n');
+ return this;
});
}
+
}
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/bin/vmservice/vmservice_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698