DalaDev.Ports (dala_dev v0.4.0)

Copy Markdown View Source

Maps dala's per-device ports and finds host-side squatters.

Two failure modes this makes visible:

  • A stale process (old iproxy, leftover dev server, a previous app instance) is already listening on a port the next device needs.
  • You can't remember which dist/LV port belongs to which device when something misbehaves.

Port model:

  • EPMD — 4369, shared by all devices on the host
  • dist — Tunnel.dist_port(index) (9100 + index) per discovered device, using the same index order as the deployer/connector
  • LiveView — hashed from the app name in [4200..4999], matching the hash-based port allocation in Dala.LiveView.local_url/1

Summary

Types

One expected port binding: which device uses it and for what.

Functions

Kills the given host PIDs with SIGKILL. Returns count actually signalled.

Returns pids of host processes listening on port, as integers. Empty list means the port is free. Uses lsof (macOS/Linux).

Expected LiveView port for this project — same formula as dala's hash-based default (4200 + rem(phash2(app_name), 800)). Public for testing.

Builds the expected port map for currently connected devices. Android devices come first (deployer index order), then iOS.

Types

entry()

@type entry() :: %{
  device: String.t(),
  id: String.t() | nil,
  kind: :epmd | :dist | :liveview,
  port: non_neg_integer(),
  node: atom() | nil
}

One expected port binding: which device uses it and for what.

Functions

kill_pids(pids)

@spec kill_pids([non_neg_integer()]) :: non_neg_integer()

Kills the given host PIDs with SIGKILL. Returns count actually signalled.

listeners_on(port)

@spec listeners_on(non_neg_integer()) :: [non_neg_integer()]

Returns pids of host processes listening on port, as integers. Empty list means the port is free. Uses lsof (macOS/Linux).

liveview_port()

@spec liveview_port() :: non_neg_integer()

Expected LiveView port for this project — same formula as dala's hash-based default (4200 + rem(phash2(app_name), 800)). Public for testing.

port_map(lister \\ &default_lister/0)

@spec port_map((-> [DalaDev.Device.t()])) :: [entry()]

Builds the expected port map for currently connected devices. Android devices come first (deployer index order), then iOS.

lister/0 overrides discovery (test seam — mirrors NativeBuild.narrow_platforms_for_device/3).