mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Signed-off-by: Stewart X Addison <sxa@ibm.com> PR-URL: https://github.com/nodejs/node/pull/62238 Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
39 lines
984 B
JavaScript
39 lines
984 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const os = require('os');
|
|
if (common.isWindows)
|
|
common.skip('dgram clustering is currently not supported on windows.');
|
|
if (common.isAIX && os.release() === '7.3')
|
|
common.skip('dgram clutering with reuse does not work if built on AIX 7.3.');
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|