-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: allow shared reused dgram sockets
Allow listening on reused dgram ports in cluster workers. Fix: nodejs/node-v0.x-archive#9261 PR-URL: #2548 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Showing
4 changed files
with
87 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const dgram = require('dgram'); | ||
|
||
if (common.isWindows) { | ||
console.log('1..0 # Skipped: dgram clustering is currently not supported ' + | ||
'on windows.'); | ||
return; | ||
} | ||
|
||
if (cluster.isMaster) { | ||
cluster.fork().on('exit', function(code) { | ||
assert.equal(code, 0); | ||
}); | ||
return; | ||
} | ||
|
||
const sockets = []; | ||
function next() { | ||
sockets.push(this); | ||
if (sockets.length !== 2) | ||
return; | ||
|
||
// Work around health check issue | ||
process.nextTick(function() { | ||
for (var i = 0; i < sockets.length; i++) | ||
sockets[i].close(close); | ||
}); | ||
} | ||
|
||
var waiting = 2; | ||
function close() { | ||
if (--waiting === 0) | ||
cluster.worker.disconnect(); | ||
} | ||
|
||
for (var i = 0; i < 2; i++) | ||
dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next); |