| 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:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| 11 import 'dart:vmservice'; | 11 import 'dart:vmservice'; |
| 12 | 12 |
| 13 part 'loader.dart'; | |
| 14 part 'resources.dart'; | 13 part 'resources.dart'; |
| 15 part 'server.dart'; | 14 part 'server.dart'; |
| 16 | 15 |
| 17 // The TCP ip/port that the HTTP server listens on. | 16 // The TCP ip/port that the HTTP server listens on. |
| 18 int _port; | 17 int _port; |
| 19 String _ip; | 18 String _ip; |
| 20 // Should the HTTP server auto start? | 19 // Should the HTTP server auto start? |
| 21 bool _autoStart; | 20 bool _autoStart; |
| 22 | 21 |
| 23 bool _isWindows = false; | 22 bool _isWindows = false; |
| 24 | 23 |
| 25 var _signalWatch; | |
| 26 | |
| 27 // HTTP servr. | 24 // HTTP servr. |
| 28 Server server; | 25 Server server; |
| 29 Future<Server> serverFuture; | 26 Future<Server> serverFuture; |
| 30 | 27 |
| 31 void _bootServer() { | 28 void _bootServer() { |
| 32 // Load resources. | 29 // Load resources. |
| 33 _triggerResourceLoad(); | 30 _triggerResourceLoad(); |
| 34 // Lazily create service. | 31 // Lazily create service. |
| 35 var service = new VMService(); | 32 var service = new VMService(); |
| 36 // Lazily create server. | 33 // Lazily create server. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 50 _bootServer(); | 47 _bootServer(); |
| 51 } | 48 } |
| 52 // Toggle HTTP server. | 49 // Toggle HTTP server. |
| 53 if (server.running) { | 50 if (server.running) { |
| 54 serverFuture = server.shutdown(true).then(_clearFuture); | 51 serverFuture = server.shutdown(true).then(_clearFuture); |
| 55 } else { | 52 } else { |
| 56 serverFuture = server.startup().then(_clearFuture); | 53 serverFuture = server.startup().then(_clearFuture); |
| 57 } | 54 } |
| 58 } | 55 } |
| 59 | 56 |
| 60 void _registerSignalHandler() { | 57 void _registerSignalHandler(Stream signalWatch(ProcessSignal signal)) { |
| 61 if (_isWindows) { | 58 if (_isWindows) { |
| 62 // Cannot register for signals on Windows. | 59 // Cannot register for signals on Windows. |
| 63 return; | 60 return; |
| 64 } | 61 } |
| 65 _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); | 62 signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); |
| 66 } | 63 } |
| 67 | 64 |
| 68 const _shortDelay = const Duration(milliseconds: 10); | 65 main(Stream signalWatch(ProcessSignal signal)) { |
| 69 | |
| 70 main() { | |
| 71 if (_autoStart) { | 66 if (_autoStart) { |
| 72 _bootServer(); | 67 _bootServer(); |
| 73 server.startup(); | 68 server.startup(); |
| 74 // It's just here to push an event on the event loop so that we invoke the | |
| 75 // scheduled microtasks. | |
| 76 Timer.run(() {}); | |
| 77 } | 69 } |
| 78 scriptLoadPort.handler = _processLoadRequest; | 70 _registerSignalHandler(signalWatch); |
| 79 // Register signal handler after a small delay to avoid stalling main | |
| 80 // isolate startup. | |
| 81 new Timer(_shortDelay, _registerSignalHandler); | |
| 82 return scriptLoadPort; | |
| 83 } | 71 } |
| OLD | NEW |