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

Side by Side Diff: runtime/bin/vmservice/vmservice_io.dart

Issue 1030013002: Shutdown the service isolate when shutting down the VM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 10 matching lines...) Expand all
21 bool _autoStart; 21 bool _autoStart;
22 22
23 bool _isWindows = false; 23 bool _isWindows = false;
24 24
25 var _signalWatch; 25 var _signalWatch;
26 26
27 // HTTP servr. 27 // HTTP servr.
28 Server server; 28 Server server;
29 Future<Server> serverFuture; 29 Future<Server> serverFuture;
30 30
31 void _bootServer() { 31 _onShutdown() {
32 if (server != null) {
33 server.close(true).catchError((e, st) => null);
zra 2015/03/24 21:53:59 Maybe the catchError should assert() so that we at
Cutch 2015/03/24 23:39:07 Done.
34 }
35 }
36
37 _bootServer() {
zra 2015/03/24 21:53:59 Why drop the return types?
Cutch 2015/03/24 23:39:07 I'm omitting 'void' return types in Dart code.
32 // Load resources. 38 // Load resources.
33 _triggerResourceLoad(); 39 _triggerResourceLoad();
34 // Lazily create service. 40 // Lazily create service.
35 var service = new VMService(); 41 var service = new VMService();
42 service.onShutdown = _onShutdown;
36 // Lazily create server. 43 // Lazily create server.
37 server = new Server(service, _ip, _port); 44 server = new Server(service, _ip, _port);
38 } 45 }
39 46
40 void _clearFuture(_) { 47 _clearFuture(_) {
41 serverFuture = null; 48 serverFuture = null;
42 } 49 }
43 50
44 void _onSignal(ProcessSignal signal) { 51 _onSignal(ProcessSignal signal) {
45 if (serverFuture != null) { 52 if (serverFuture != null) {
46 // Still waiting. 53 // Still waiting.
47 return; 54 return;
48 } 55 }
49 if (server == null) { 56 if (server == null) {
50 _bootServer(); 57 _bootServer();
51 } 58 }
52 // Toggle HTTP server. 59 // Toggle HTTP server.
53 if (server.running) { 60 if (server.running) {
54 serverFuture = server.shutdown(true).then(_clearFuture); 61 serverFuture = server.shutdown(true).then(_clearFuture);
55 } else { 62 } else {
56 serverFuture = server.startup().then(_clearFuture); 63 serverFuture = server.startup().then(_clearFuture);
57 } 64 }
58 } 65 }
59 66
60 void _registerSignalHandler() { 67 _registerSignalHandler() {
61 if (_isWindows) { 68 if (_isWindows) {
62 // Cannot register for signals on Windows. 69 // Cannot register for signals on Windows.
63 return; 70 return;
64 } 71 }
65 _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); 72 _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal);
66 } 73 }
67 74
68 const _shortDelay = const Duration(milliseconds: 10); 75 const _shortDelay = const Duration(milliseconds: 10);
69 76
70 main() { 77 main() {
71 if (_autoStart) { 78 if (_autoStart) {
72 _bootServer(); 79 _bootServer();
73 server.startup(); 80 server.startup();
74 // It's just here to push an event on the event loop so that we invoke the 81 // It's just here to push an event on the event loop so that we invoke the
75 // scheduled microtasks. 82 // scheduled microtasks.
76 Timer.run(() {}); 83 Timer.run(() {});
77 } 84 }
78 scriptLoadPort.handler = _processLoadRequest; 85 scriptLoadPort.handler = _processLoadRequest;
79 // Register signal handler after a small delay to avoid stalling main 86 // Register signal handler after a small delay to avoid stalling main
80 // isolate startup. 87 // isolate startup.
81 new Timer(_shortDelay, _registerSignalHandler); 88 new Timer(_shortDelay, _registerSignalHandler);
82 return scriptLoadPort; 89 return scriptLoadPort;
83 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698