@@ -391,17 +391,17 @@ end
391
391
392
392
@testset " Local-machine broadcast" begin
393
393
let a, b, c
394
- # (Mac OS X's loopback interface doesn't support broadcasts)
394
+ # Apple does not support broadcasting on 127.255.255.255
395
395
bcastdst = Sys. isapple () ? ip " 255.255.255.255" : ip " 127.255.255.255"
396
396
397
- function create_socket ()
397
+ function create_socket (addr :: IPAddr , port )
398
398
s = UDPSocket ()
399
- bind (s, ip " 0.0.0.0 " , 2000 , reuseaddr = true , enable_broadcast = true )
400
- s
399
+ bind (s, addr, port , reuseaddr = true , enable_broadcast = true )
400
+ return s
401
401
end
402
402
403
- function wait_with_timeout (recvs)
404
- TIMEOUT_VAL = 3 * 1e9 # nanoseconds
403
+ # Wait for futures to finish with a given timeout
404
+ function wait_with_timeout (recvs, TIMEOUT_VAL = 3 * 1e9 )
405
405
t0 = time_ns ()
406
406
recvs_check = copy (recvs)
407
407
while ((length (filter! (t-> ! istaskdone (t), recvs_check)) > 0 )
@@ -412,23 +412,55 @@ end
412
412
map (wait, recvs)
413
413
end
414
414
415
- a, b, c = [create_socket () for i = 1 : 3 ]
415
+ # First, test IPv4 broadcast
416
+ port = 2000
417
+ a, b, c = [create_socket (ip " 0.0.0.0" , port) for i in 1 : 3 ]
416
418
try
417
- # bsd family do not allow broadcasting to ip"255.255.255.255"
418
- # or ip"127.255.255.255"
419
+ # bsd family do not allow broadcasting on loopbacks
419
420
@static if ! Sys. isbsd () || Sys. isapple ()
420
- send (c, bcastdst, 2000 , " hello" )
421
+ send (c, bcastdst, port , " hello" )
421
422
recvs = [@async @test String (recv (s)) == " hello" for s in (a, b)]
422
423
wait_with_timeout (recvs)
423
424
end
424
425
catch e
425
426
if isa (e, Base. IOError) && Base. uverrorname (e. code) == " EPERM"
426
- @warn " UDP broadcast test skipped (permission denied upon send, restrictive firewall?)"
427
+ @warn " UDP IPv4 broadcast test skipped (permission denied upon send, restrictive firewall?)"
427
428
else
428
429
rethrow ()
429
430
end
430
431
end
431
432
[close (s) for s in [a, b, c]]
433
+
434
+ # Test ipv6 broadcast groups
435
+ a, b, c = [create_socket (ip " ::" , port) for i in 1 : 3 ]
436
+ try
437
+ # Exemplary Interface-local ipv6 multicast group, if we wanted this to actually be routed
438
+ # to other computers, we should use a link-local or larger address scope group
439
+ # bsd family and darwin do not allow broadcasting on loopbacks
440
+ @static if ! Sys. isbsd () && ! Sys. isapple ()
441
+ group = ip " ff11::6a75:6c69:61"
442
+ join_multicast_group (a, group)
443
+ join_multicast_group (b, group)
444
+
445
+ send (c, group, port, " hello" )
446
+ recvs = [@async @test String (recv (s)) == " hello" for s in (a, b)]
447
+ wait_with_timeout (recvs)
448
+
449
+ leave_multicast_group (a, group)
450
+ leave_multicast_group (b, group)
451
+
452
+ send (c, group, port, " hello" )
453
+ recvs = [@async @test String (recv (s)) == " hello" for s in (a, b)]
454
+ # We only wait 200ms since we're pretty sure this is going to time out
455
+ @test_throws ErrorException wait_with_timeout (recvs, 2e8 )
456
+ end
457
+ catch e
458
+ if isa (e, Base. IOError) && Base. uverrorname (e. code) == " EPERM"
459
+ @warn " UDP IPv6 broadcast test skipped (permission denied upon send, restrictive firewall?)"
460
+ else
461
+ rethrow ()
462
+ end
463
+ end
432
464
end
433
465
end
434
466
0 commit comments