• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasIPv6)
5  common.skip('no IPv6 support');
6if (common.isWindows)
7  common.skip('dgram clustering is currently not supported on windows.');
8
9const assert = require('assert');
10const cluster = require('cluster');
11const dgram = require('dgram');
12
13// This test ensures that the `ipv6Only` option in `dgram.createSock()`
14// works as expected.
15if (cluster.isMaster) {
16  cluster.fork().on('exit', common.mustCall((code) => {
17    assert.strictEqual(code, 0);
18  }));
19} else {
20  let waiting = 2;
21  function close() {
22    if (--waiting === 0)
23      cluster.worker.disconnect();
24  }
25
26  const socket1 = dgram.createSocket({
27    type: 'udp6',
28    ipv6Only: true
29  });
30  const socket2 = dgram.createSocket({
31    type: 'udp4',
32  });
33  socket1.on('error', common.mustNotCall());
34  socket2.on('error', common.mustNotCall());
35
36  socket1.bind({
37    port: 0,
38    address: '::',
39  }, common.mustCall(() => {
40    const { port } = socket1.address();
41    socket2.bind({
42      port,
43      address: '0.0.0.0',
44    }, common.mustCall(() => {
45      process.nextTick(() => {
46        socket1.close(close);
47        socket2.close(close);
48      });
49    }));
50  }));
51}
52