File tree Expand file tree Collapse file tree 3 files changed +32
-15
lines changed Expand file tree Collapse file tree 3 files changed +32
-15
lines changed Original file line number Diff line number Diff line change 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 11'use strict' ;
2- require ( '../common' ) ;
2+ const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
44const dgram = require ( 'dgram' ) ;
55const socket = dgram . createSocket ( 'udp4' ) ;
6- let thrown = false ;
76
87socket . 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 ) ;
1111
1212 //Try to set an invalid TTL (valid ttl is > 0 and < 256)
13- try {
13+ assert . throws ( ( ) => {
1414 socket . setMulticastTTL ( 1000 ) ;
15- } catch ( e ) {
16- thrown = true ;
17- }
15+ } , / ^ E r r o r : s e t M u l t i c a s t T T L E I N V A L $ / ) ;
1816
19- assert ( thrown , 'Setting an invalid multicast TTL should throw some error' ) ;
17+ assert . throws ( ( ) => {
18+ socket . setMulticastTTL ( 'foo' ) ;
19+ } , / ^ T y p e E r r o r : A r g u m e n t m u s t b e a n u m b e r $ / ) ;
2020
2121 //close the socket
2222 socket . close ( ) ;
23- } ) ;
23+ } ) ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
2- require ( '../common' ) ;
2+ const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
44const dgram = require ( 'dgram' ) ;
55const socket = dgram . createSocket ( 'udp4' ) ;
66
77socket . bind ( 0 ) ;
8- socket . on ( 'listening' , function ( ) {
8+ socket . on ( 'listening' , common . mustCall ( ( ) => {
99 const result = socket . setTTL ( 16 ) ;
1010 assert . strictEqual ( result , 16 ) ;
1111
12- assert . throws ( function ( ) {
12+ assert . throws ( ( ) => {
1313 socket . setTTL ( 'foo' ) ;
14- } , / A r g u m e n t m u s t b e a n u m b e r / ) ;
14+ } , / ^ T y p e E r r o r : A r g u m e n t m u s t b e a n u m b e r $ / ) ;
15+
16+ // TTL must be a number from > 0 to < 256
17+ assert . throws ( ( ) => {
18+ socket . setTTL ( 1000 ) ;
19+ } , / ^ E r r o r : s e t T T L E I N V A L $ / ) ;
1520
1621 socket . close ( ) ;
17- } ) ;
22+ } ) ) ;
You can’t perform that action at this time.
0 commit comments