socket.rb: remove closed checks

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-11-15 01:39:11 +00:00
parent 9d6569ff40
commit 6394b63db9

View File

@ -71,7 +71,7 @@ class Addrinfo
begin begin
yield sock yield sock
ensure ensure
sock.close if !sock.closed? sock.close
end end
else else
sock sock
@ -185,7 +185,7 @@ class Addrinfo
begin begin
yield sock yield sock
ensure ensure
sock.close if !sock.closed? sock.close
end end
else else
sock sock
@ -208,7 +208,7 @@ class Addrinfo
begin begin
yield sock yield sock
ensure ensure
sock.close if !sock.closed? sock.close
end end
else else
sock sock
@ -617,7 +617,7 @@ class Socket < BasicSocket
Addrinfo.foreach(host, port, nil, :STREAM) {|ai| Addrinfo.foreach(host, port, nil, :STREAM) {|ai|
if local_addr_list if local_addr_list
local_addr = local_addr_list.find {|local_ai| local_ai.afamily == ai.afamily } local_addr = local_addr_list.find {|local_ai| local_ai.afamily == ai.afamily }
next if !local_addr next unless local_addr
else else
local_addr = nil local_addr = nil
end end
@ -632,7 +632,7 @@ class Socket < BasicSocket
ret = sock ret = sock
break break
} }
if !ret unless ret
if last_error if last_error
raise last_error raise last_error
else else
@ -643,7 +643,7 @@ class Socket < BasicSocket
begin begin
yield ret yield ret
ensure ensure
ret.close if !ret.closed? ret.close
end end
else else
ret ret
@ -667,7 +667,7 @@ class Socket < BasicSocket
if reuseaddr if reuseaddr
s.setsockopt(:SOCKET, :REUSEADDR, 1) s.setsockopt(:SOCKET, :REUSEADDR, 1)
end end
if !port unless port
s.bind(ai) s.bind(ai)
port = s.local_address.ip_port port = s.local_address.ip_port
else else
@ -766,7 +766,7 @@ class Socket < BasicSocket
begin begin
yield sockets yield sockets
ensure ensure
sockets.each {|s| s.close if !s.closed? } sockets.each {|s| s.close }
end end
else else
sockets sockets
@ -885,12 +885,12 @@ class Socket < BasicSocket
Addrinfo.foreach(host, port, nil, :DGRAM, nil, Socket::AI_PASSIVE) {|ai| Addrinfo.foreach(host, port, nil, :DGRAM, nil, Socket::AI_PASSIVE) {|ai|
if ai.ipv4? && ai.ip_address == "0.0.0.0" if ai.ipv4? && ai.ip_address == "0.0.0.0"
local_addrs.each {|a| local_addrs.each {|a|
next if !a.ipv4? next unless a.ipv4?
ip_list << Addrinfo.new(a.to_sockaddr, :INET, :DGRAM, 0); ip_list << Addrinfo.new(a.to_sockaddr, :INET, :DGRAM, 0);
} }
elsif ai.ipv6? && ai.ip_address == "::" && !ipv6_recvpktinfo elsif ai.ipv6? && ai.ip_address == "::" && !ipv6_recvpktinfo
local_addrs.each {|a| local_addrs.each {|a|
next if !a.ipv6? next unless a.ipv6?
ip_list << Addrinfo.new(a.to_sockaddr, :INET6, :DGRAM, 0); ip_list << Addrinfo.new(a.to_sockaddr, :INET6, :DGRAM, 0);
} }
else else
@ -927,7 +927,7 @@ class Socket < BasicSocket
begin begin
yield sockets yield sockets
ensure ensure
sockets.each {|s| s.close if !s.closed? } if sockets sockets.each {|s| s.close } if sockets
end end
else else
sockets sockets
@ -1064,7 +1064,7 @@ class Socket < BasicSocket
begin begin
yield sock yield sock
ensure ensure
sock.close if !sock.closed? sock.close
end end
else else
sock sock
@ -1088,7 +1088,7 @@ class Socket < BasicSocket
# } # }
# #
def self.unix_server_socket(path) def self.unix_server_socket(path)
if !unix_socket_abstract_name?(path) unless unix_socket_abstract_name?(path)
begin begin
st = File.lstat(path) st = File.lstat(path)
rescue Errno::ENOENT rescue Errno::ENOENT
@ -1102,8 +1102,8 @@ class Socket < BasicSocket
begin begin
yield s yield s
ensure ensure
s.close if !s.closed? s.close
if !unix_socket_abstract_name?(path) unless unix_socket_abstract_name?(path)
File.unlink path File.unlink path
end end
end end