| 384 | } |
| 385 | |
| 386 | private async connectTcp(timeoutMs: number): Promise<void> { |
| 387 | const { host, port } = this.tcpEndpoint! |
| 388 | return new Promise((resolve, reject) => { |
| 389 | const timer = setTimeout(() => { |
| 390 | reject( |
| 391 | new Error( |
| 392 | `TCP connection to "${this.targetName}" at ${host}:${port} timed out after ${timeoutMs}ms`, |
| 393 | ), |
| 394 | ) |
| 395 | }, timeoutMs) |
| 396 | |
| 397 | const socket = createConnection({ host, port }, () => { |
| 398 | clearTimeout(timer) |
| 399 | this.socket = socket |
| 400 | this.setupSocketListeners(socket) |
| 401 | this.emit('connected') |
| 402 | resolve() |
| 403 | }) |
| 404 | |
| 405 | socket.on('error', err => { |
| 406 | clearTimeout(timer) |
| 407 | socket.destroy() |
| 408 | reject(err) |
| 409 | }) |
| 410 | }) |
| 411 | } |
| 412 | |
| 413 | private async connectUds(timeoutMs: number): Promise<void> { |
| 414 | const { access } = await import('fs/promises') |