MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / chooseDaemonPort

Function chooseDaemonPort

apps/cli/src/daemon.ts:293–311  ·  view source on GitHub ↗
(input: {
  preferredPort: number;
  hostname: string;
})

Source from the content-addressed store, hash-verified

291 });
292
293export const chooseDaemonPort = (input: {
294 preferredPort: number;
295 hostname: string;
296}): Effect.Effect<number, Error> =>
297 Effect.gen(function* () {
298 const preferredAvailable = yield* isPortAvailable({
299 hostname: input.hostname,
300 port: input.preferredPort,
301 });
302 if (preferredAvailable) return input.preferredPort;
303
304 const fallbackPort = yield* pickEphemeralPort(input.hostname);
305 if (!Number.isFinite(fallbackPort) || fallbackPort <= 0 || fallbackPort > 65535) {
306 return yield* Effect.fail(
307 new Error(`Could not find an available daemon port for host ${input.hostname}`),
308 );
309 }
310 return fallbackPort;
311 });
312
313// ---------------------------------------------------------------------------
314// Service-install planning (pure)

Callers 2

spawnDaemonAsLockHolderFunction · 0.90

Calls 2

isPortAvailableFunction · 0.85
pickEphemeralPortFunction · 0.85

Tested by

no test coverage detected