Follow r56795.  Since Ruby 2.2, calling #close on a closed
socket no longer raises exceptions.

* lib/cgi/session.rb (update): remove closed? check
* lib/net/http.rb (finish, transport_request): ditto
* lib/net/imap.rb (disconnect): ditto
* lib/net/pop.rb (do_start, do_finish): ditto
* lib/net/smtp.rb (do_start, do_finish): ditto
* lib/open3.rb (popen_run, pipeline_run): ditto
* lib/pstore.rb (transaction): ditto
* lib/shell/process-controller.rb (sfork):
* lib/tempfile (_close, call, Tempfile.create): ditto
* lib/webrick/httpauth/htdigest.rb (flush): ditto
* lib/webrick/httpauth/htpasswd.rb (flush): ditto
* lib/webrick/server.rb (start_thread, cleanup_shutdown_pipe): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2016-11-21 23:05:41 +00:00
Родитель 8e4c8e9642
Коммит f845a9ef76
12 изменённых файлов: 23 добавлений и 27 удалений

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

@ -426,7 +426,7 @@ class CGI
f.close f.close
File.rename @path+".new", @path File.rename @path+".new", @path
ensure ensure
f.close if f and !f.closed? f.close if f
lockf.close if lockf lockf.close if lockf
end end
end end

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

@ -978,7 +978,7 @@ module Net #:nodoc:
def do_finish def do_finish
@started = false @started = false
@socket.close if @socket and not @socket.closed? @socket.close if @socket
@socket = nil @socket = nil
end end
private :do_finish private :do_finish
@ -1463,12 +1463,12 @@ module Net #:nodoc:
Timeout::Error => exception Timeout::Error => exception
if count == 0 && IDEMPOTENT_METHODS_.include?(req.method) if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
count += 1 count += 1
@socket.close if @socket and not @socket.closed? @socket.close if @socket
D "Conn close because of error #{exception}, and retry" D "Conn close because of error #{exception}, and retry"
retry retry
end end
D "Conn close because of error #{exception}" D "Conn close because of error #{exception}"
@socket.close if @socket and not @socket.closed? @socket.close if @socket
raise raise
end end
@ -1476,7 +1476,7 @@ module Net #:nodoc:
res res
rescue => exception rescue => exception
D "Conn close because of error #{exception}" D "Conn close because of error #{exception}"
@socket.close if @socket and not @socket.closed? @socket.close if @socket
raise exception raise exception
end end

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

@ -329,10 +329,8 @@ module Net
end end
@receiver_thread.join @receiver_thread.join
synchronize do synchronize do
unless @sock.closed?
@sock.close @sock.close
end end
end
raise e if e raise e if e
end end

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

@ -570,7 +570,7 @@ module Net
ensure ensure
# Authentication failed, clean up connection. # Authentication failed, clean up connection.
unless @started unless @started
s.close if s and not s.closed? s.close if s
@socket = nil @socket = nil
@command = nil @command = nil
end end
@ -601,7 +601,7 @@ module Net
ensure ensure
@started = false @started = false
@command = nil @command = nil
@socket.close if @socket and not @socket.closed? @socket.close if @socket
@socket = nil @socket = nil
end end
private :do_finish private :do_finish

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

@ -567,7 +567,7 @@ module Net
ensure ensure
unless @started unless @started
# authentication failed, cancel connection. # authentication failed, cancel connection.
s.close if s and not s.closed? s.close if s
@socket = nil @socket = nil
end end
end end
@ -613,7 +613,7 @@ module Net
ensure ensure
@started = false @started = false
@error_occurred = false @error_occurred = false
@socket.close if @socket and not @socket.closed? @socket.close if @socket
@socket = nil @socket = nil
end end

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

@ -204,7 +204,7 @@ module Open3
begin begin
return yield(*result) return yield(*result)
ensure ensure
parent_io.each{|io| io.close unless io.closed?} parent_io.each{|io| io.close }
wait_thr.join wait_thr.join
end end
end end
@ -655,7 +655,7 @@ module Open3
begin begin
return yield(*result) return yield(*result)
ensure ensure
parent_io.each{|io| io.close unless io.closed?} parent_io.each{|io| io.close }
wait_thrs.each {|t| t.join } wait_thrs.each {|t| t.join }
end end
end end

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

@ -335,7 +335,7 @@ class PStore
save_data(checksum, original_data_size, file) save_data(checksum, original_data_size, file)
end end
ensure ensure
file.close if !file.closed? file.close
end end
else else
# This can only occur if read_only == true. # This can only occur if read_only == true.

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

@ -260,7 +260,7 @@ class Shell
ObjectSpace.each_object(IO) do |io| ObjectSpace.each_object(IO) do |io|
if ![STDIN, STDOUT, STDERR].include?(io) if ![STDIN, STDOUT, STDERR].include?(io)
io.close unless io.closed? io.close
end end
end end

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

@ -147,7 +147,7 @@ class Tempfile < DelegateClass(File)
end end
def _close # :nodoc: def _close # :nodoc:
@tmpfile.close unless @tmpfile.closed? @tmpfile.close
end end
protected :_close protected :_close
@ -252,7 +252,7 @@ class Tempfile < DelegateClass(File)
warn "removing #{@tmpfile.path}..." if $DEBUG warn "removing #{@tmpfile.path}..." if $DEBUG
@tmpfile.close unless @tmpfile.closed? @tmpfile.close
begin begin
File.unlink(@tmpfile.path) File.unlink(@tmpfile.path)
rescue Errno::ENOENT rescue Errno::ENOENT
@ -334,7 +334,7 @@ def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)
begin begin
yield tmpfile yield tmpfile
ensure ensure
tmpfile.close if !tmpfile.closed? tmpfile.close
File.unlink tmpfile File.unlink tmpfile
end end
else else

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

@ -79,7 +79,7 @@ module WEBrick
File::rename(tmp.path, output) File::rename(tmp.path, output)
renamed = true renamed = true
ensure ensure
tmp.close if !tmp.closed? tmp.close
File.unlink(tmp.path) if !renamed File.unlink(tmp.path) if !renamed
end end
end end

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

@ -84,7 +84,7 @@ module WEBrick
File::rename(tmp.path, output) File::rename(tmp.path, output)
renamed = true renamed = true
ensure ensure
tmp.close if !tmp.closed? tmp.close
File.unlink(tmp.path) if !renamed File.unlink(tmp.path) if !renamed
end end
end end

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

@ -309,7 +309,7 @@ module WEBrick
else else
@logger.debug "close: <address unknown>" @logger.debug "close: <address unknown>"
end end
sock.close unless sock.closed? sock.close
end end
} }
end end
@ -334,12 +334,10 @@ module WEBrick
@shutdown_pipe = nil @shutdown_pipe = nil
return if !shutdown_pipe return if !shutdown_pipe
shutdown_pipe.each {|io| shutdown_pipe.each {|io|
if !io.closed?
begin begin
io.close io.close
rescue IOError # another thread closed io. rescue IOError # another thread closed io.
end end
end
} }
end end