summaryrefslogtreecommitdiff
path: root/lib/rinda
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-01 02:37:27 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-01 02:37:27 +0000
commit09ab3a0a9f9fa7d3f091bec988c52b9f8ed62b41 (patch)
treea0d0e7232577c4f0503aadf7dde99ed7a5a14afe /lib/rinda
parentf64541d7bd37590207b43868edc6f54811a4906d (diff)
* lib/rinda/ring.rb (RingFinger#make_socket): Close the socket on exception.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rinda')
-rw-r--r--lib/rinda/ring.rb30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/rinda/ring.rb b/lib/rinda/ring.rb
index deef114..e36c93b 100644
--- a/lib/rinda/ring.rb
+++ b/lib/rinda/ring.rb
@@ -413,22 +413,26 @@ module Rinda
addrinfo = Addrinfo.udp(address, @port)
soc = Socket.new(addrinfo.pfamily, addrinfo.socktype, addrinfo.protocol)
+ begin
+ if addrinfo.ipv4_multicast? then
+ soc.setsockopt(Socket::Option.ipv4_multicast_loop(1))
+ soc.setsockopt(Socket::Option.ipv4_multicast_ttl(@multicast_hops))
+ elsif addrinfo.ipv6_multicast? then
+ soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_LOOP, true)
+ soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS,
+ [@multicast_hops].pack('I'))
+ soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_IF,
+ [@multicast_interface].pack('I'))
+ else
+ soc.setsockopt(:SOL_SOCKET, :SO_BROADCAST, true)
+ end
- if addrinfo.ipv4_multicast? then
- soc.setsockopt(Socket::Option.ipv4_multicast_loop(1))
- soc.setsockopt(Socket::Option.ipv4_multicast_ttl(@multicast_hops))
- elsif addrinfo.ipv6_multicast? then
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_LOOP, true)
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS,
- [@multicast_hops].pack('I'))
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_IF,
- [@multicast_interface].pack('I'))
- else
- soc.setsockopt(:SOL_SOCKET, :SO_BROADCAST, true)
+ soc.connect(addrinfo)
+ rescue Exception
+ soc.close
+ raise
end
- soc.connect(addrinfo)
-
soc
end