(host: string, port: number, timeoutMs: number)
| 67 | } |
| 68 | |
| 69 | function tcpConnect(host: string, port: number, timeoutMs: number): Promise<boolean> { |
| 70 | return new Promise((res) => { |
| 71 | const sock = connect({ host, port }); |
| 72 | const done = (ok: boolean) => { |
| 73 | sock.destroy(); |
| 74 | res(ok); |
| 75 | }; |
| 76 | sock.setTimeout(timeoutMs); |
| 77 | sock.once('connect', () => done(true)); |
| 78 | sock.once('timeout', () => done(false)); |
| 79 | sock.once('error', () => done(false)); |
| 80 | }); |
| 81 | } |
| 82 | |
| 83 | async function tcpReachable(port: number, timeoutMs = 2000): Promise<boolean> { |
| 84 | const [v4, v6] = await Promise.all([ |
no test coverage detected