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

ruby-changes:44722

From: nobu <ko1@a...>
Date: Tue, 15 Nov 2016 10:39:17 +0900 (JST)
Subject: [ruby-changes:44722] nobu:r56795 (trunk): socket.rb: remove closed checks

nobu	2016-11-15 10:39:11 +0900 (Tue, 15 Nov 2016)

  New Revision: 56795

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

  Log:
    socket.rb: remove closed checks
    
    * ext/socket/lib/socket.rb: remove unnecessary closed checks,
      close on closed socket no longer raises an exception.

  Modified files:
    trunk/ext/socket/lib/socket.rb
Index: ext/socket/lib/socket.rb
===================================================================
--- ext/socket/lib/socket.rb	(revision 56794)
+++ ext/socket/lib/socket.rb	(revision 56795)
@@ -71,7 +71,7 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L71
       begin
         yield sock
       ensure
-        sock.close if !sock.closed?
+        sock.close
       end
     else
       sock
@@ -185,7 +185,7 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L185
       begin
         yield sock
       ensure
-        sock.close if !sock.closed?
+        sock.close
       end
     else
       sock
@@ -208,7 +208,7 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L208
       begin
         yield sock
       ensure
-        sock.close if !sock.closed?
+        sock.close
       end
     else
       sock
@@ -617,7 +617,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L617
     Addrinfo.foreach(host, port, nil, :STREAM) {|ai|
       if local_addr_list
         local_addr = local_addr_list.find {|local_ai| local_ai.afamily == ai.afamily }
-        next if !local_addr
+        next unless local_addr
       else
         local_addr = nil
       end
@@ -632,7 +632,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L632
       ret = sock
       break
     }
-    if !ret
+    unless ret
       if last_error
         raise last_error
       else
@@ -643,7 +643,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L643
       begin
         yield ret
       ensure
-        ret.close if !ret.closed?
+        ret.close
       end
     else
       ret
@@ -667,7 +667,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L667
         if reuseaddr
           s.setsockopt(:SOCKET, :REUSEADDR, 1)
         end
-        if !port
+        unless port
           s.bind(ai)
           port = s.local_address.ip_port
         else
@@ -766,7 +766,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L766
       begin
         yield sockets
       ensure
-        sockets.each {|s| s.close if !s.closed? }
+        sockets.each {|s| s.close }
       end
     else
       sockets
@@ -885,12 +885,12 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L885
     Addrinfo.foreach(host, port, nil, :DGRAM, nil, Socket::AI_PASSIVE) {|ai|
       if ai.ipv4? && ai.ip_address == "0.0.0.0"
         local_addrs.each {|a|
-          next if !a.ipv4?
+          next unless a.ipv4?
           ip_list << Addrinfo.new(a.to_sockaddr, :INET, :DGRAM, 0);
         }
       elsif ai.ipv6? && ai.ip_address == "::" && !ipv6_recvpktinfo
         local_addrs.each {|a|
-          next if !a.ipv6?
+          next unless a.ipv6?
           ip_list << Addrinfo.new(a.to_sockaddr, :INET6, :DGRAM, 0);
         }
       else
@@ -927,7 +927,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L927
       begin
         yield sockets
       ensure
-        sockets.each {|s| s.close if !s.closed? } if sockets
+        sockets.each {|s| s.close } if sockets
       end
     else
       sockets
@@ -1064,7 +1064,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L1064
       begin
         yield sock
       ensure
-        sock.close if !sock.closed?
+        sock.close
       end
     else
       sock
@@ -1088,7 +1088,7 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L1088
   #   }
   #
   def self.unix_server_socket(path)
-    if !unix_socket_abstract_name?(path)
+    unless unix_socket_abstract_name?(path)
       begin
         st = File.lstat(path)
       rescue Errno::ENOENT
@@ -1102,8 +1102,8 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L1102
       begin
         yield s
       ensure
-        s.close if !s.closed?
-        if !unix_socket_abstract_name?(path)
+        s.close
+        unless unix_socket_abstract_name?(path)
           File.unlink path
         end
       end

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

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