| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 570d334 commit 5fc4b19
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,10 +20,10 @@ | |||
| 20 | 20 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
| 21 | 21 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 22 | 22 | ||
| 23 | - var common = require('../common'); | ||
| 24 | - var assert = require('assert'); | ||
| 25 | - var cluster = require('cluster'); | ||
| 26 | - var dgram = require('dgram'); | ||
| 23 | + const common = require('../common'); | ||
| 24 | + const assert = require('assert'); | ||
| 25 | + const cluster = require('cluster'); | ||
| 26 | + const dgram = require('dgram'); | ||
| 27 | 27 | ||
| 28 | 28 | // Without an explicit bind, send() causes an implicit bind, which always | |
| 29 | 29 | // generate a unique per-socket ephemeral port. An explicit bind to a port | |
@@ -40,17 +40,21 @@ var dgram = require('dgram'); | |||
| 40 | 40 | // with ENOTSUP. | |
| 41 | 41 | ||
| 42 | 42 | if (cluster.isMaster) { | |
| 43 | - var pass; | ||
| 44 | 43 | var messages = 0; | |
| 45 | - var ports = {}; | ||
| 46 | - | ||
| 47 | - process.on('exit', function() { | ||
| 48 | - assert.strictEqual(pass, true); | ||
| 49 | - }); | ||
| 44 | + const ports = {}; | ||
| 45 | + const pids = []; | ||
| 50 | 46 | ||
| 51 | 47 | var target = dgram.createSocket('udp4'); | |
| 52 | 48 | ||
| 49 | + const done = common.mustCall(function() { | ||
| 50 | + cluster.disconnect(); | ||
| 51 | + target.close(); | ||
| 52 | + }); | ||
| 53 | + | ||
| 53 | 54 | target.on('message', function(buf, rinfo) { | |
| 55 | + if (pids.includes(buf.toString())) | ||
| 56 | + return; | ||
| 57 | + pids.push(buf.toString()); | ||
| 54 | 58 | messages++; | |
| 55 | 59 | ports[rinfo.port] = true; | |
| 56 | 60 | ||
@@ -63,12 +67,6 @@ if (cluster.isMaster) { | |||
| 63 | 67 | assert.strictEqual(Object.keys(ports).length, 3); | |
| 64 | 68 | done(); | |
| 65 | 69 | } | |
| 66 | - | ||
| 67 | - function done() { | ||
| 68 | - pass = true; | ||
| 69 | - cluster.disconnect(); | ||
| 70 | - target.close(); | ||
| 71 | - } | ||
| 72 | 70 | }); | |
| 73 | 71 | ||
| 74 | 72 | target.on('listening', function() { | |
@@ -85,7 +83,12 @@ if (cluster.isMaster) { | |||
| 85 | 83 | return; | |
| 86 | 84 | } | |
| 87 | 85 | ||
| 88 | - var source = dgram.createSocket('udp4'); | ||
| 86 | + const source = dgram.createSocket('udp4'); | ||
| 87 | + var interval; | ||
| 88 | + | ||
| 89 | + source.on('close', function() { | ||
| 90 | + clearInterval(interval); | ||
| 91 | + }); | ||
| 89 | 92 | ||
| 90 | 93 | if (process.env.BOUND === 'y') { | |
| 91 | 94 | source.bind(0); | |
@@ -96,4 +99,7 @@ if (process.env.BOUND === 'y') { | |||
| 96 | 99 | source.unref(); | |
| 97 | 100 | } | |
| 98 | 101 | ||
| 99 | - source.send(Buffer.from('abc'), 0, 3, common.PORT, '127.0.0.1'); | ||
| 102 | + const buf = Buffer.from(process.pid.toString()); | ||
| 103 | + interval = setInterval(() => { | ||
| 104 | + source.send(buf, common.PORT, '127.0.0.1'); | ||
| 105 | + }, 1).unref(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments