[ruby/rinda] Handle situations where IPv4 multicast is not available

Fixes [Bug #13864]

https://github.com/ruby/rinda/commit/3cd620f38c
This commit is contained in:
Jeremy Evans 2021-08-06 15:36:33 -07:00 коммит произвёл git
Родитель cb12d7c71b
Коммит 89aa09afaf
1 изменённых файлов: 41 добавлений и 30 удалений

Просмотреть файл

@ -583,6 +583,22 @@ class TupleSpaceProxyTest < Test::Unit::TestCase
end
end
module RingIPv4
def ipv4_mc(rf)
begin
v4mc = rf.make_socket('239.0.0.1')
rescue Errno::ENETUNREACH, Errno::ENOBUFS, Errno::ENODEV
omit 'IPv4 multicast not available'
end
begin
yield v4mc
ensure
v4mc.close
end
end
end
module RingIPv6
def prepare_ipv6(r)
begin
@ -625,6 +641,7 @@ module RingIPv6
end
class TestRingServer < Test::Unit::TestCase
include RingIPv4
def setup
@port = Rinda::Ring_PORT
@ -697,27 +714,23 @@ class TestRingServer < Test::Unit::TestCase
end
def test_make_socket_ipv4_multicast
begin
v4mc = @rs.make_socket('239.0.0.1')
rescue Errno::ENOBUFS => e
omit "Missing multicast support in OS: #{e.message}"
end
begin
if Socket.const_defined?(:SO_REUSEPORT) then
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEPORT).bool)
else
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEADDR).bool)
ipv4_mc(@rs) do |v4mc|
begin
if Socket.const_defined?(:SO_REUSEPORT) then
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEPORT).bool)
else
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEADDR).bool)
end
rescue TypeError
if /aix/ =~ RUBY_PLATFORM
omit "Known bug in getsockopt(2) on AIX"
end
raise $!
end
rescue TypeError
if /aix/ =~ RUBY_PLATFORM
omit "Known bug in getsockopt(2) on AIX"
end
raise $!
end
assert_equal('0.0.0.0', v4mc.local_address.ip_address)
assert_equal(@port, v4mc.local_address.ip_port)
assert_equal('0.0.0.0', v4mc.local_address.ip_address)
assert_equal(@port, v4mc.local_address.ip_port)
end
end
def test_make_socket_ipv6_multicast
@ -746,7 +759,7 @@ class TestRingServer < Test::Unit::TestCase
@rs.shutdown
begin
@rs = Rinda::RingServer.new(@ts, [['239.0.0.1', '0.0.0.0']], @port)
rescue Errno::ENOBUFS => e
rescue Errno::ENOBUFS, Errno::ENODEV => e
omit "Missing multicast support in OS: #{e.message}"
end
@ -848,6 +861,7 @@ end
class TestRingFinger < Test::Unit::TestCase
include RingIPv6
include RingIPv4
def setup
@rf = Rinda::RingFinger.new
@ -867,12 +881,10 @@ class TestRingFinger < Test::Unit::TestCase
end
def test_make_socket_ipv4_multicast
v4mc = @rf.make_socket('239.0.0.1')
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_LOOP).ipv4_multicast_loop)
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
ensure
v4mc.close if v4mc
ipv4_mc(@rf) do |v4mc|
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_LOOP).ipv4_multicast_loop)
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
end
end
def test_make_socket_ipv6_multicast
@ -884,10 +896,9 @@ class TestRingFinger < Test::Unit::TestCase
def test_make_socket_ipv4_multicast_hops
@rf.multicast_hops = 2
v4mc = @rf.make_socket('239.0.0.1')
assert_equal(2, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
ensure
v4mc.close if v4mc
ipv4_mc(@rf) do |v4mc|
assert_equal(2, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
end
end
def test_make_socket_ipv6_multicast_hops