1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/webrick/server.rb: Less instance variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-11-10 03:46:22 +00:00
parent e62fe866e5
commit 230fb3ceae
2 changed files with 28 additions and 17 deletions

View file

@ -1,3 +1,7 @@
Mon Nov 10 12:44:39 2014 Tanaka Akira <akr@fsij.org>
* lib/webrick/server.rb: Less instance variables.
Mon Nov 10 12:19:43 2014 Tanaka Akira <akr@fsij.org> Mon Nov 10 12:19:43 2014 Tanaka Akira <akr@fsij.org>
* lib/webrick/server.rb (shutdown): Use close() on @shutdown_pipe_w to * lib/webrick/server.rb (shutdown): Use close() on @shutdown_pipe_w to

View file

@ -106,7 +106,7 @@ module WEBrick
@logger.info("ruby #{rubyv}") @logger.info("ruby #{rubyv}")
@listeners = [] @listeners = []
@shutdown_pipe_r = @shutdown_pipe_w = nil @shutdown_pipe = nil
unless @config[:DoNotListen] unless @config[:DoNotListen]
if @config[:Listen] if @config[:Listen]
warn(":Listen option is deprecated; use GenericServer#listen") warn(":Listen option is deprecated; use GenericServer#listen")
@ -115,7 +115,7 @@ module WEBrick
if @config[:Port] == 0 if @config[:Port] == 0
@config[:Port] = @listeners[0].addr[1] @config[:Port] = @listeners[0].addr[1]
end end
@shutdown_pipe_r, @shutdown_pipe_w = IO.pipe @shutdown_pipe = IO.pipe
end end
end end
@ -164,13 +164,15 @@ module WEBrick
"#{self.class}#start: pid=#{$$} port=#{@config[:Port]}" "#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
call_callback(:StartCallback) call_callback(:StartCallback)
shutdown_pipe = @shutdown_pipe
thgroup = ThreadGroup.new thgroup = ThreadGroup.new
@status = :Running @status = :Running
begin begin
while @status == :Running while @status == :Running
begin begin
if svrs = IO.select([@shutdown_pipe_r, *@listeners], nil, nil, 2.0) if svrs = IO.select([shutdown_pipe[0], *@listeners], nil, nil, 2.0)
if svrs[0].include? @shutdown_pipe_r if svrs[0].include? shutdown_pipe[0]
break break
end end
svrs[0].each{|svr| svrs[0].each{|svr|
@ -197,7 +199,7 @@ module WEBrick
end end
end end
ensure ensure
cleanup_shutdown_pipe cleanup_shutdown_pipe(shutdown_pipe)
cleanup_listener cleanup_listener
@status = :Shutdown @status = :Shutdown
@logger.info "going to shutdown ..." @logger.info "going to shutdown ..."
@ -225,11 +227,13 @@ module WEBrick
def shutdown def shutdown
stop stop
shutdown_pipe_w = @shutdown_pipe_w # another thread may modify @shutdown_pipe_w. shutdown_pipe = @shutdown_pipe # another thread may modify @shutdown_pipe.
if shutdown_pipe_w && !shutdown_pipe_w.closed? if shutdown_pipe
begin if !shutdown_pipe[1].closed?
shutdown_pipe_w.close begin
rescue IOError # closed by another thread. shutdown_pipe[1].close
rescue IOError # closed by another thread.
end
end end
end end
end end
@ -317,13 +321,16 @@ module WEBrick
end end
end end
def cleanup_shutdown_pipe def cleanup_shutdown_pipe(shutdown_pipe)
@shutdown_pipe_r.close @shutdown_pipe = nil
begin shutdown_pipe.each {|io|
@shutdown_pipe_w.close if !io.closed?
rescue IOError # another thread closed @shutdown_pipe_w. begin
end io.close
@shutdown_pipe_r = @shutdown_pipe_w = nil rescue IOError # another thread closed io.
end
end
}
end end
def cleanup_listener def cleanup_listener