[前][次][番号順一覧][スレッド一覧]

ruby-changes:34229

From: akr <ko1@a...>
Date: Mon, 2 Jun 2014 09:56:38 +0900 (JST)
Subject: [ruby-changes:34229] akr:r46292 (trunk): * lib/rinda/ring.rb (RingFinger#make_socket): Close the socket on exception.

akr	2014-06-01 11:37:27 +0900 (Sun, 01 Jun 2014)

  New Revision: 46292

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=46292&view=revision

  Log:
    * lib/rinda/ring.rb (RingFinger#make_socket): Close the socket on exception.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rinda/ring.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46291)
+++ ChangeLog	(revision 46292)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun  1 11:36:25 2014  Tanaka Akira  <akr@f...>
+
+	* lib/rinda/ring.rb (RingFinger#make_socket): Close the socket on
+	  exception.
+
 Sun Jun  1 06:55:26 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (intern_str): dynamic attrset ID is registered by
Index: lib/rinda/ring.rb
===================================================================
--- lib/rinda/ring.rb	(revision 46291)
+++ lib/rinda/ring.rb	(revision 46292)
@@ -413,22 +413,26 @@ module Rinda https://github.com/ruby/ruby/blob/trunk/lib/rinda/ring.rb#L413
       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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]