mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
15164cebce
Doc deprecate isMaster and setupMaster in favor of isPrimary and setupPrimary. Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: https://github.com/nodejs/node/pull/36478 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Beth Griggs <bgriggs@redhat.com>
41 lines
883 B
JavaScript
41 lines
883 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const net = require('net');
|
|
|
|
if (cluster.isPrimary) {
|
|
const buf = Buffer.from('foobar');
|
|
|
|
cluster.setupPrimary({
|
|
stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'pipe']
|
|
});
|
|
|
|
const worker = cluster.fork();
|
|
const channel = worker.process.stdio[4];
|
|
let response = '';
|
|
|
|
worker.on('exit', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 0);
|
|
assert.strictEqual(signal, null);
|
|
}));
|
|
|
|
channel.setEncoding('utf8');
|
|
channel.on('data', (data) => {
|
|
response += data;
|
|
|
|
if (response === buf.toString()) {
|
|
worker.disconnect();
|
|
}
|
|
});
|
|
channel.write(buf);
|
|
} else {
|
|
const pipe = new net.Socket({ fd: 4 });
|
|
|
|
pipe.unref();
|
|
pipe.on('data', (data) => {
|
|
assert.ok(data instanceof Buffer);
|
|
pipe.write(data);
|
|
});
|
|
}
|