11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (common.isWindows) 41cb0ef41Sopenharmony_ci common.skip('dgram clustering is currently not supported on windows.'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst cluster = require('cluster'); 81cb0ef41Sopenharmony_ciconst dgram = require('dgram'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciif (cluster.isPrimary) { 111cb0ef41Sopenharmony_ci cluster.fork(); 121cb0ef41Sopenharmony_ci} else { 131cb0ef41Sopenharmony_ci // When the socket attempts to bind, it requests a handle from the cluster. 141cb0ef41Sopenharmony_ci // Close the socket before returning the handle from the cluster. 151cb0ef41Sopenharmony_ci const socket = dgram.createSocket('udp4'); 161cb0ef41Sopenharmony_ci const _getServer = cluster._getServer; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci cluster._getServer = common.mustCall(function(self, options, callback) { 191cb0ef41Sopenharmony_ci socket.close(common.mustCall(() => { 201cb0ef41Sopenharmony_ci _getServer.call(this, self, options, common.mustCall((err, handle) => { 211cb0ef41Sopenharmony_ci assert.strictEqual(err, 0); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci // When the socket determines that it was already closed, it will 241cb0ef41Sopenharmony_ci // close the handle. Use handle.close() to terminate the test. 251cb0ef41Sopenharmony_ci const close = handle.close; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci handle.close = common.mustCall(function() { 281cb0ef41Sopenharmony_ci setImmediate(() => cluster.worker.disconnect()); 291cb0ef41Sopenharmony_ci return close.call(this); 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci callback(err, handle); 331cb0ef41Sopenharmony_ci })); 341cb0ef41Sopenharmony_ci })); 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci socket.bind(common.mustNotCall('Socket should not bind.')); 381cb0ef41Sopenharmony_ci} 39