| 34 | primary(); |
| 35 | |
| 36 | function primary() { |
| 37 | // spawn() can only create one IPC channel so we use stdin/stdout as an |
| 38 | // ad-hoc command channel. |
| 39 | const proc = spawn(process.execPath, [ |
| 40 | '--expose-internals', __filename, 'worker', |
| 41 | ], { |
| 42 | stdio: ['pipe', 'pipe', 'pipe', 'ipc'] |
| 43 | }); |
| 44 | let handle = null; |
| 45 | proc.on('exit', () => { |
| 46 | handle.close(); |
| 47 | }); |
| 48 | proc.stdout.on('data', common.mustCall((data) => { |
| 49 | assert.strictEqual(data.toString(), 'ok\r\n'); |
| 50 | net.createServer(common.mustNotCall()).listen(0, function() { |
| 51 | handle = this._handle; |
| 52 | proc.send('one'); |
| 53 | proc.send('two', handle); |
| 54 | proc.send('three'); |
| 55 | proc.stdin.write('ok\r\n'); |
| 56 | }); |
| 57 | })); |
| 58 | proc.stderr.pipe(process.stderr); |
| 59 | } |
| 60 | |
| 61 | function worker() { |
| 62 | const { kChannelHandle } = require('internal/child_process'); |