vmProcesses function

Future<VmProcesses> vmProcesses(
  1. int port
)

Finds the processes behind the VM service at port and checks both; owner and app are null when they cannot be resolved to exactly one process.

Implementation

Future<VmProcesses> vmProcesses(int port) async {
  final owners = await portOwners(port);
  if (owners.pids.length != 1) return _noVmProcesses;
  final owner = owners.pids.single;
  final (ownerCommand, ownerCheck) = await (processCommand(owner), checkProcess(owner)).wait;
  if (_isSimulatorApp(ownerCommand)) {
    final peer = ownerCheck.life == ProcessLife.stopped ? null : await _stoppedPeer(port, owner);
    return (
      owner: owner,
      ownerCommand: ownerCommand,
      ownerCheck: ownerCheck,
      app: owner,
      appCommand: ownerCommand,
      appCheck: ownerCheck,
      stoppedPeer: peer?.pid,
      stoppedPeerCommand: peer?.command,
      stoppedPeerState: peer?.state,
    );
  }
  final found = <int, String>{};
  for (final remote in (await _outboundPorts(owner, port)).take(12)) {
    for (final pid in (await portOwners(remote)).pids) {
      final command = await processCommand(pid);
      if (pid != owner && _isSimulatorApp(command)) found[pid] = command!;
    }
  }
  final app = found.length == 1 ? found.keys.single : null;
  return (
    owner: owner,
    ownerCommand: ownerCommand,
    ownerCheck: ownerCheck,
    app: app,
    appCommand: app == null ? null : found[app],
    appCheck: app == null ? null : await checkProcess(app),
    stoppedPeer: null,
    stoppedPeerCommand: null,
    stoppedPeerState: null,
  );
}