Index: runtime/bin/vmservice/vmservice_io.dart |
diff --git a/runtime/bin/vmservice/vmservice_io.dart b/runtime/bin/vmservice/vmservice_io.dart |
index 3816aa2f940224a3f941e35f6a4a73a3da70a112..410b917284918b7882fcc98449b7032e5ba54a66 100644 |
--- a/runtime/bin/vmservice/vmservice_io.dart |
+++ b/runtime/bin/vmservice/vmservice_io.dart |
@@ -21,45 +21,40 @@ String _ip; |
bool _autoStart; |
bool _isWindows = false; |
- |
var _signalWatch; |
var _signalSubscription; |
// HTTP server. |
Server server; |
Future<Server> serverFuture; |
-HashMap<String, Asset> _assets; |
-HashMap<String, Asset> get assets { |
- if (_assets == null) { |
- try { |
- _assets = Asset.request(); |
- } catch (e) { |
- print('Could not load Observatory assets: $e'); |
- } |
- } |
- return _assets; |
-} |
-_onShutdown() { |
+_lazyServerBoot() { |
if (server != null) { |
- server.close(true).catchError((e, st) { |
- print("Error in vm-service shutdown: $e\n$st\n"); |
- }); |
- } |
- if (_signalSubscription != null) { |
- _signalSubscription.cancel(); |
- _signalSubscription = null; |
+ return; |
} |
-} |
- |
-_bootServer() { |
// Lazily create service. |
var service = new VMService(); |
- service.onShutdown = _onShutdown; |
// Lazily create server. |
server = new Server(service, _ip, _port); |
} |
+Future cleanupCallback() async { |
+ // Cancel the sigquit subscription. |
+ if (_signalSubscription != null) { |
+ await _signalSubscription.cancel(); |
+ _signalSubscription = null; |
+ } |
+ if (server != null) { |
+ try { |
+ await server.cleanup(true); |
+ } catch (e, st) { |
+ print("Error in vm-service shutdown: $e\n$st\n"); |
+ } |
+ } |
+ // Call out to embedder's shutdown callback. |
+ _shutdown(); |
+} |
+ |
_clearFuture(_) { |
serverFuture = null; |
} |
@@ -69,9 +64,7 @@ _onSignal(ProcessSignal signal) { |
// Still waiting. |
return; |
} |
- if (server == null) { |
- _bootServer(); |
- } |
+ _lazyServerBoot(); |
// Toggle HTTP server. |
if (server.running) { |
serverFuture = server.shutdown(true).then(_clearFuture); |
@@ -81,6 +74,10 @@ _onSignal(ProcessSignal signal) { |
} |
_registerSignalHandler() { |
+ if (_signalWatch == null) { |
+ // Cannot register for signals. |
+ return; |
+ } |
if (_isWindows) { |
// Cannot register for signals on Windows. |
return; |
@@ -88,28 +85,21 @@ _registerSignalHandler() { |
_signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); |
} |
-const _shortDelay = const Duration(milliseconds: 10); |
- |
main() { |
+ // Set embedder hooks. |
+ VMServiceEmbedderHooks.cleanup = cleanupCallback; |
if (_autoStart) { |
- _bootServer(); |
+ _lazyServerBoot(); |
server.startup(); |
// It's just here to push an event on the event loop so that we invoke the |
// scheduled microtasks. |
Timer.run(() {}); |
} |
- // TODO(johnmccutchan, turnidge) Creating a VMService object here causes |
- // strange behavior from the legacy debug protocol and coverage tool. |
- // Enable this code, and remove the call to Isolate::KillIsolate() from |
- // service_isolate.cc when the strange behavior is solved. |
- // See: https://github.com/dart-lang/sdk/issues/23977 |
zra
2016/01/28 18:40:04
It looks like this issue is still open. What is th
Cutch
2016/01/28 23:49:45
The legacy debug protocol has been removed and the
zra
2016/01/29 02:58:18
So, we can either get rid of this `else` branch, o
Cutch
2016/01/29 15:36:52
I've left a TODO.
|
- // else { |
- // var service = new VMService(); |
- // service.onShutdown = _onShutdown; |
- // } |
scriptLoadPort.handler = _processLoadRequest; |
// Register signal handler after a small delay to avoid stalling main |
// isolate startup. |
- new Timer(_shortDelay, _registerSignalHandler); |
+ new Timer(shortDelay, _registerSignalHandler); |
return scriptLoadPort; |
} |
+ |
+_shutdown() native "VMServiceIO_Shutdown"; |