| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const dgram = require('dgram'); | ||
| 5 | + const socket = dgram.createSocket('udp4'); | ||
| 6 | + | ||
| 7 | + socket.bind(0); | ||
| 8 | + socket.on('listening', common.mustCall(() => { | ||
| 9 | + const result = socket.setMulticastLoopback(16); | ||
| 10 | + assert.strictEqual(result, 16); | ||
| 11 | + socket.close(); | ||
| 12 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,23 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const dgram = require('dgram'); | |
| 5 | 5 | const socket = dgram.createSocket('udp4'); | |
| 6 | - let thrown = false; | ||
| 7 | 6 | ||
| 8 | 7 | socket.bind(0); | |
| 9 | - socket.on('listening', function() { | ||
| 10 | - socket.setMulticastTTL(16); | ||
| 8 | + socket.on('listening', common.mustCall(() => { | ||
| 9 | + const result = socket.setMulticastTTL(16); | ||
| 10 | + assert.strictEqual(result, 16); | ||
| 11 | 11 | ||
| 12 | 12 | //Try to set an invalid TTL (valid ttl is > 0 and < 256) | |
| 13 | - try { | ||
| 13 | + assert.throws(() => { | ||
| 14 | 14 | socket.setMulticastTTL(1000); | |
| 15 | - } catch (e) { | ||
| 16 | - thrown = true; | ||
| 17 | - } | ||
| 15 | + }, /^Error: setMulticastTTL EINVAL$/); | ||
| 18 | 16 | ||
| 19 | - assert(thrown, 'Setting an invalid multicast TTL should throw some error'); | ||
| 17 | + assert.throws(() => { | ||
| 18 | + socket.setMulticastTTL('foo'); | ||
| 19 | + }, /^TypeError: Argument must be a number$/); | ||
| 20 | 20 | ||
| 21 | 21 | //close the socket | |
| 22 | 22 | socket.close(); | |
| 23 | - }); | ||
| 23 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,22 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const dgram = require('dgram'); | |
| 5 | 5 | const socket = dgram.createSocket('udp4'); | |
| 6 | 6 | ||
| 7 | 7 | socket.bind(0); | |
| 8 | - socket.on('listening', function() { | ||
| 9 | - var result = socket.setTTL(16); | ||
| 8 | + socket.on('listening', common.mustCall(() => { | ||
| 9 | + const result = socket.setTTL(16); | ||
| 10 | 10 | assert.strictEqual(result, 16); | |
| 11 | 11 | ||
| 12 | - assert.throws(function() { | ||
| 12 | + assert.throws(() => { | ||
| 13 | 13 | socket.setTTL('foo'); | |
| 14 | - }, /Argument must be a number/); | ||
| 14 | + }, /^TypeError: Argument must be a number$/); | ||
| 15 | + | ||
| 16 | + // TTL must be a number from > 0 to < 256 | ||
| 17 | + assert.throws(() => { | ||
| 18 | + socket.setTTL(1000); | ||
| 19 | + }, /^Error: setTTL EINVAL$/); | ||
| 15 | 20 | ||
| 16 | 21 | socket.close(); | |
| 17 | - }); | ||
| 22 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments