OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library vmservice_io; | 5 library vmservice_io; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (server != null) { | 32 if (server != null) { |
33 return; | 33 return; |
34 } | 34 } |
35 // Lazily create service. | 35 // Lazily create service. |
36 var service = new VMService(); | 36 var service = new VMService(); |
37 // Lazily create server. | 37 // Lazily create server. |
38 server = new Server(service, _ip, _port); | 38 server = new Server(service, _ip, _port); |
39 } | 39 } |
40 | 40 |
41 Future cleanupCallback() async { | 41 Future cleanupCallback() async { |
| 42 shutdownLoaders(); |
42 // Cancel the sigquit subscription. | 43 // Cancel the sigquit subscription. |
43 if (_signalSubscription != null) { | 44 if (_signalSubscription != null) { |
44 await _signalSubscription.cancel(); | 45 await _signalSubscription.cancel(); |
45 _signalSubscription = null; | 46 _signalSubscription = null; |
46 } | 47 } |
47 if (server != null) { | 48 if (server != null) { |
48 try { | 49 try { |
49 await server.cleanup(true); | 50 await server.cleanup(true); |
50 } catch (e, st) { | 51 } catch (e, st) { |
51 print("Error in vm-service shutdown: $e\n$st\n"); | 52 print("Error in vm-service shutdown: $e\n$st\n"); |
(...skipping 29 matching lines...) Expand all Loading... |
81 if (_isWindows) { | 82 if (_isWindows) { |
82 // Cannot register for signals on Windows. | 83 // Cannot register for signals on Windows. |
83 return; | 84 return; |
84 } | 85 } |
85 _signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); | 86 _signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); |
86 } | 87 } |
87 | 88 |
88 main() { | 89 main() { |
89 // Set embedder hooks. | 90 // Set embedder hooks. |
90 VMServiceEmbedderHooks.cleanup = cleanupCallback; | 91 VMServiceEmbedderHooks.cleanup = cleanupCallback; |
| 92 // Always instantiate the vmservice object so that the exit message |
| 93 // can be delivered and waiting loaders can be cancelled. |
| 94 var service = new VMService(); |
91 if (_autoStart) { | 95 if (_autoStart) { |
92 _lazyServerBoot(); | 96 _lazyServerBoot(); |
93 server.startup(); | 97 server.startup(); |
94 // It's just here to push an event on the event loop so that we invoke the | 98 // It's just here to push an event on the event loop so that we invoke the |
95 // scheduled microtasks. | 99 // scheduled microtasks. |
96 Timer.run(() {}); | 100 Timer.run(() {}); |
97 } | 101 } |
98 // TODO(johnmccutchan): Fixup service isolate shutdown in the general case. | |
99 // See ServiceIsolate::KillServiceIsolate and ServiceIsolate::Shutdown. | |
100 scriptLoadPort.handler = _processLoadRequest; | 102 scriptLoadPort.handler = _processLoadRequest; |
101 // Register signal handler after a small delay to avoid stalling main | 103 // Register signal handler after a small delay to avoid stalling main |
102 // isolate startup. | 104 // isolate startup. |
103 new Timer(shortDelay, _registerSignalHandler); | 105 new Timer(shortDelay, _registerSignalHandler); |
104 return scriptLoadPort; | 106 return scriptLoadPort; |
105 } | 107 } |
106 | 108 |
107 _shutdown() native "VMServiceIO_Shutdown"; | 109 _shutdown() native "VMServiceIO_Shutdown"; |
OLD | NEW |