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>
36 lines
834 B
JavaScript
36 lines
834 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (common.isWindows)
|
|
common.skip('dgram clustering is currently not supported on windows.');
|
|
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const dgram = require('dgram');
|
|
|
|
if (cluster.isPrimary) {
|
|
cluster.fork().on('exit', common.mustCall((code) => {
|
|
assert.strictEqual(code, 0);
|
|
}));
|
|
return;
|
|
}
|
|
|
|
let waiting = 2;
|
|
function close() {
|
|
if (--waiting === 0)
|
|
cluster.worker.disconnect();
|
|
}
|
|
|
|
const options = { type: 'udp4', reuseAddr: true };
|
|
const socket1 = dgram.createSocket(options);
|
|
const socket2 = dgram.createSocket(options);
|
|
|
|
socket1.bind(0, () => {
|
|
socket2.bind(socket1.address().port, () => {
|
|
// Work around health check issue
|
|
process.nextTick(() => {
|
|
socket1.close(close);
|
|
socket2.close(close);
|
|
});
|
|
});
|
|
});
|