private CliResult tryConnect(List<String> args, Path currentDirectory) throws IOException {
    var pf = myFallbackMode ? StandardProtocolFamily.INET : StandardProtocolFamily.UNIX;
    try (var socketChannel = SocketChannel.open(pf); var selector = Selector.open()) {
      socketChannel.configureBlocking(false);

      SocketAddress address;
      if (myFallbackMode) {
        var port = 0;
        try { port = Integer.parseInt(Files.readString(myPortFile)); }
        catch (NumberFormatException e) { throw new SocketException("Invalid port; " + e.getMessage()); }
        address = new InetSocketAddress(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), port);
      }
      else if (myRedirectedPortFile != null) {
        address = UnixDomainSocketAddress.of(Files.readString(myPortFile));
      }
      else {
        address = UnixDomainSocketAddress.of(myPortFile);
      }

      if (LOG.isDebugEnabled()) LOG.debug("connecting to " + address);
      socketChannel.register(selector, SelectionKey.OP_CONNECT);
      if (!socketChannel.connect(address)) {
        if (selector.select(TIMEOUT_MS) == 0) throw timeoutException(address, "connection failed");
        socketChannel.finishConnect();
      }
      LOG.debug("... connected");
      socketChannel.register(selector, SelectionKey.OP_READ);

      allowActivation();

      var request = new ArrayList<String>(args.size() + 1);
      request.add(currentDirectory.toString());
      request.addAll(args);
      sendLines(socketChannel, request);

      if (selector.select(TIMEOUT_MS) == 0) throw timeoutException(address, "no response");
      var ack = receiveLines(socketChannel);
      if (!ack.equals(ACK_PACKET)) throw new IOException(BootstrapBundle.message("bootstrap.error.malformed.response", ack));

      var response = receiveLines(socketChannel);
      if (response.size() != 2) throw new IOException(BootstrapBundle.message("bootstrap.error.malformed.response", response));
      var exitCode = Integer.parseInt(response.get(0));
      var message = response.get(1);
      return new CliResult(exitCode, message.isEmpty() ? null : message);
    }
  }
private CliResult tryConnect(List<String> args, Path currentDirectory)