MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / canBind

Function canBind

apps/kimi-code/src/cli/sub/server/daemon.ts:89–97  ·  view source on GitHub ↗

True when `host:port` is currently free to bind (nothing listening).

(host: string, port: number)

Source from the content-addressed store, hash-verified

87
88/** True when `host:port` is currently free to bind (nothing listening). */
89function canBind(host: string, port: number): Promise<boolean> {
90 return new Promise((resolvePromise) => {
91 const probe = createServer();
92 probe.once('error', () => resolvePromise(false));
93 probe.listen({ host, port }, () => {
94 probe.close(() => resolvePromise(true));
95 });
96 });
97}
98
99/** Ask the OS for an ephemeral free port on `host`. */
100function getFreePort(host: string): Promise<number> {

Callers 1

resolveDaemonPortFunction · 0.85

Calls 3

onceMethod · 0.65
listenMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected