| 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:mirrors'; |
| 11 import 'dart:vmservice'; | 12 import 'dart:vmservice'; |
| 12 | 13 |
| 13 part 'resources.dart'; | 14 part 'resources.dart'; |
| 14 part 'server.dart'; | 15 part 'server.dart'; |
| 15 | 16 |
| 16 // The TCP ip/port that the HTTP server listens on. | 17 // The TCP ip/port that the HTTP server listens on. |
| 17 int _port; | 18 int _port; |
| 18 String _ip; | 19 String _ip; |
| 20 // Should the HTTP server auto start? |
| 21 bool _autoStart; |
| 22 |
| 23 // HTTP servr. |
| 24 Server server; |
| 25 Future<Server> serverFuture; |
| 19 | 26 |
| 20 // The VM service instance. | 27 // The VM service instance. |
| 21 VMService service; | 28 VMService service; |
| 22 | 29 |
| 30 void _onSignal(ProcessSignal signal) { |
| 31 if (serverFuture != null) { |
| 32 // Still waiting. |
| 33 return; |
| 34 } |
| 35 // Toggle HTTP server. |
| 36 if (server.running) { |
| 37 serverFuture = server.shutdown(true).then((_) { |
| 38 serverFuture = null; |
| 39 }); |
| 40 } else { |
| 41 serverFuture = server.startup().then((_) { |
| 42 serverFuture = null; |
| 43 }); |
| 44 } |
| 45 } |
| 46 |
| 23 main() { | 47 main() { |
| 24 // Get VMService. | 48 // Get VMService. |
| 25 service = new VMService(); | 49 service = new VMService(); |
| 26 // Start HTTP server. | 50 // Start HTTP server. |
| 27 var server = new Server(service, _ip, _port); | 51 server = new Server(service, _ip, _port); |
| 28 server.startServer(); | 52 if (_autoStart) { |
| 53 server.startup(); |
| 54 } |
| 55 |
| 56 bool useSIGQUIT = true; |
| 57 // Listen for SIGQUIT. |
| 58 if (useSIGQUIT) { |
| 59 var io = currentMirrorSystem().findLibrary(const Symbol('dart.io')); |
| 60 var c = MirrorSystem.getSymbol('_ProcessUtils', io); |
| 61 var m = MirrorSystem.getSymbol('_watchSignalInternal', io); |
| 62 var processUtils = io.declarations[c]; |
| 63 processUtils.invoke(m, [ProcessSignal.SIGQUIT]).reflectee.listen(_onSignal); |
| 64 } else { |
| 65 ProcessSignal.SIGUSR1.watch().listen(_onSignal); |
| 66 } |
| 29 } | 67 } |
| 68 |
| OLD | NEW |