| 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 part of vmservice_io; | 5 part of vmservice_io; |
| 6 | 6 |
| 7 final bool silentObservatory = | 7 final bool silentObservatory = |
| 8 const bool.fromEnvironment('SILENT_OBSERVATORY'); | 8 const bool.fromEnvironment('SILENT_OBSERVATORY'); |
| 9 | 9 |
| 10 void serverPrint(String s) { | 10 void serverPrint(String s) { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 var addresses = await InternetAddress.lookup(_ip); | 337 var addresses = await InternetAddress.lookup(_ip); |
| 338 // Prefer IPv4 addresses. | 338 // Prefer IPv4 addresses. |
| 339 for (var i = 0; i < addresses.length; i++) { | 339 for (var i = 0; i < addresses.length; i++) { |
| 340 address = addresses[i]; | 340 address = addresses[i]; |
| 341 if (address.type == InternetAddressType.IP_V4) break; | 341 if (address.type == InternetAddressType.IP_V4) break; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 _server = await HttpServer.bind(address, _port); | 344 _server = await HttpServer.bind(address, _port); |
| 345 _server.listen(_requestHandler, cancelOnError: true); | 345 _server.listen(_requestHandler, cancelOnError: true); |
| 346 serverPrint('Observatory listening on $serverAddress'); | 346 serverPrint('Observatory listening on $serverAddress'); |
| 347 if (Platform.isFuchsia) { |
| 348 // Create a file with the port number. |
| 349 String tmp = Directory.systemTemp.path; |
| 350 String path = "$tmp/dart.services/${_server.port}"; |
| 351 serverPrint("Creating $path"); |
| 352 new File(path)..createSync(recursive: true); |
| 353 } |
| 347 // Server is up and running. | 354 // Server is up and running. |
| 348 _notifyServerState(serverAddress.toString()); | 355 _notifyServerState(serverAddress.toString()); |
| 349 onServerAddressChange('$serverAddress'); | 356 onServerAddressChange('$serverAddress'); |
| 350 return this; | 357 return this; |
| 351 } catch (e, st) { | 358 } catch (e, st) { |
| 352 serverPrint('Could not start Observatory HTTP server:\n$e\n$st\n'); | 359 serverPrint('Could not start Observatory HTTP server:\n$e\n$st\n'); |
| 353 _notifyServerState(""); | 360 _notifyServerState(""); |
| 354 onServerAddressChange(null); | 361 onServerAddressChange(null); |
| 355 return this; | 362 return this; |
| 356 } | 363 } |
| 357 } | 364 } |
| 358 | 365 |
| 359 Future cleanup(bool force) { | 366 Future cleanup(bool force) { |
| 360 if (_server == null) { | 367 if (_server == null) { |
| 361 return new Future.value(null); | 368 return new Future.value(null); |
| 362 } | 369 } |
| 370 if (Platform.isFuchsia) { |
| 371 // Remove the file with the port number. |
| 372 String tmp = Directory.systemTemp.path; |
| 373 String path = "$tmp/dart.services/${_server.port}"; |
| 374 serverPrint("Deleting $path"); |
| 375 new File(path)..deleteSync(); |
| 376 } |
| 363 return _server.close(force: force); | 377 return _server.close(force: force); |
| 364 } | 378 } |
| 365 | 379 |
| 366 Future shutdown(bool forced) { | 380 Future shutdown(bool forced) { |
| 367 if (_server == null) { | 381 if (_server == null) { |
| 368 // Not started. | 382 // Not started. |
| 369 return new Future.value(this); | 383 return new Future.value(this); |
| 370 } | 384 } |
| 371 | 385 |
| 372 // Shutdown HTTP server and subscription. | 386 // Shutdown HTTP server and subscription. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 383 _notifyServerState(""); | 397 _notifyServerState(""); |
| 384 onServerAddressChange(null); | 398 onServerAddressChange(null); |
| 385 return this; | 399 return this; |
| 386 }); | 400 }); |
| 387 } | 401 } |
| 388 | 402 |
| 389 } | 403 } |
| 390 | 404 |
| 391 void _notifyServerState(String uri) | 405 void _notifyServerState(String uri) |
| 392 native "VMServiceIO_NotifyServerState"; | 406 native "VMServiceIO_NotifyServerState"; |
| OLD | NEW |