checkPorts static method

void checkPorts(
  1. int port,
  2. List<int> additional,
  3. List<PortConfig> ports
)

Throws an ArgumentError when an app with ports lists a port two times, in port, additional and ports together. Such a port would be bound two times (the OS allows it), with two kinds of settings. Port 0 is a free port each time, so it can repeat. With no ports it checks nothing, as before AppConfig.ports. Dox().startServer() runs it once, before any isolate starts. Else each isolate fails on its own and is started again, in a loop.

Implementation

static void checkPorts(
  int port,
  List<int> additional,
  List<PortConfig> ports,
) {
  if (ports.isEmpty) return;
  Set<int> seen = <int>{};
  List<int> all = <int>[
    port,
    ...additional,
    for (PortConfig extra in ports) extra.port,
  ];
  for (int one in all) {
    if (one != 0 && !seen.add(one)) {
      throw ArgumentError.value(one, 'ports', 'the port is listed two times');
    }
  }
}