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

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, 8 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
Index: runtime/bin/vmservice/server.dart
diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart
index 1dbbbfc5120ff03bb263cf1cdc3a37a04e1750c9..090f1316455bfa12d8896823f3884349ce28f05d 100644
--- a/runtime/bin/vmservice/server.dart
+++ b/runtime/bin/vmservice/server.dart
@@ -80,20 +80,26 @@ class HttpRequestClient extends Client {
class Server {
static const WEBSOCKET_PATH = '/ws';
- String defaultPath = '/index.html';
- int port;
+ static const SLASH_PATH = '/index.html';
+
+ final VMService _service;
+ final int _port;
+ bool _displayStatusMessages;
- final VMService service;
HttpServer _server;
+ var _subscription;
+
+ bool get running => _server != null;
- Server(this.service, this.port);
+ Server(this._service, int port) : _port = port,
+ _displayStatusMessages = (port == 0);
void _requestHandler(HttpRequest request) {
// Allow cross origin requests.
request.response.headers.add('Access-Control-Allow-Origin', '*');
final String path =
- request.uri.path == '/' ? defaultPath : request.uri.path;
+ request.uri.path == '/' ? SLASH_PATH : request.uri.path;
var resource = Resource.resources[path];
if (resource != null) {
@@ -107,28 +113,38 @@ class Server {
if (path == WEBSOCKET_PATH) {
WebSocketTransformer.upgrade(request).then((WebSocket webSocket) {
- new WebSocketClient(webSocket, service);
+ new WebSocketClient(webSocket, _service);
});
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(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;
+ Future startup() {
+ return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, _port).then((s) {
_server = s;
- _server.listen(_requestHandler);
- if (display_message) {
- print('VMService listening on port $port');
+ _subscription = _server.listen(_requestHandler);
+ if (_displayStatusMessages) {
+ print('VMService listening on port ${_server.port}');
}
return s;
});
}
+
+ void shutdown() {
+ // Force displaying of status messages if we are forcibly shutdown.
+ _displayStatusMessages = true;
Ivan Posva 2014/04/14 16:12:58 Shouldn't the fact whether you are forced to shutd
Cutch 2014/04/15 17:42:07 Done.
+ // Shutdown HTTP server and subscription.
+ var closedPort = _server.port;
+ _server.close(force: true);
+ _server = null;
+ _subscription.cancel();
+ _subscription = null;
+ if (_displayStatusMessages) {
+ print('VMService is no longer listening on port $closedPort');
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698