UNPKG

443 BJavaScriptView Raw
1const onlisten = require('on-net-listen')
2const fs = require('fs')
3const net = require('net')
4
5onlisten(function (addr) {
6 this.destroy()
7 const port = Buffer.from(addr.port + '')
8 fs.writeSync(3, port, 0, port.length)
9 signal(3, function () {
10 process.emit('beforeExit')
11 })
12})
13
14function signal (fd, cb) {
15 const s = new net.Socket({ fd, readable: true, writable: false })
16 s.unref()
17 s.on('error', () => {})
18 s.on('close', cb)
19}