11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst cluster = require('cluster'); 51cb0ef41Sopenharmony_ciconst net = require('net'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (cluster.isPrimary) { 81cb0ef41Sopenharmony_ci const buf = Buffer.from('foobar'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci cluster.setupPrimary({ 111cb0ef41Sopenharmony_ci stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'pipe'] 121cb0ef41Sopenharmony_ci }); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci const worker = cluster.fork(); 151cb0ef41Sopenharmony_ci const channel = worker.process.stdio[4]; 161cb0ef41Sopenharmony_ci let response = ''; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci worker.on('exit', common.mustCall((code, signal) => { 191cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 201cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 211cb0ef41Sopenharmony_ci })); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci channel.setEncoding('utf8'); 241cb0ef41Sopenharmony_ci channel.on('data', (data) => { 251cb0ef41Sopenharmony_ci response += data; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci if (response === buf.toString()) { 281cb0ef41Sopenharmony_ci worker.disconnect(); 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci channel.write(buf); 321cb0ef41Sopenharmony_ci} else { 331cb0ef41Sopenharmony_ci const pipe = new net.Socket({ fd: 4 }); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci pipe.unref(); 361cb0ef41Sopenharmony_ci pipe.on('data', (data) => { 371cb0ef41Sopenharmony_ci assert.ok(data instanceof Buffer); 381cb0ef41Sopenharmony_ci pipe.write(data); 391cb0ef41Sopenharmony_ci }); 401cb0ef41Sopenharmony_ci} 41