| 426 | } |
| 427 | |
| 428 | private accept(socket: Net.Socket): void { |
| 429 | // Errors are reported to the readers and writers of the stdio streams |
| 430 | socket.on("error", () => {}) |
| 431 | const onReadable = () => { |
| 432 | const header: Buffer | null = socket.read(headerLength) |
| 433 | if (header === null) return |
| 434 | socket.off("readable", onReadable) |
| 435 | const command = |
| 436 | header.length === headerLength && Crypto.timingSafeEqual(header.subarray(0, tokenLength), this.token) |
| 437 | ? this.commands.get(header.readUInt32BE(tokenLength)) |
| 438 | : undefined |
| 439 | if (command === undefined || !command.attach(header.readUInt32BE(tokenLength + 4), socket)) { |
| 440 | socket.destroy() |
| 441 | } |
| 442 | } |
| 443 | socket.on("readable", onReadable) |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Best effort, and never throws, since it runs while exits and losses are |