summaryrefslogtreecommitdiff
path: root/lib/webrick/server.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-10 03:46:22 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-10 03:46:22 +0000
commit230fb3ceae16ef5ac1ee6e2351fc5c950da5535b (patch)
tree47800cad4f9e6d4e57f12e096d8ef646c4a8e85e /lib/webrick/server.rb
parente62fe866e562ff267b353150c39b084771c34590 (diff)
* lib/webrick/server.rb: Less instance variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/server.rb')
-rw-r--r--lib/webrick/server.rb41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 9b83c84..c779d37 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -106,7 +106,7 @@ module WEBrick
@logger.info("ruby #{rubyv}")
@listeners = []
- @shutdown_pipe_r = @shutdown_pipe_w = nil
+ @shutdown_pipe = nil
unless @config[:DoNotListen]
if @config[:Listen]
warn(":Listen option is deprecated; use GenericServer#listen")
@@ -115,7 +115,7 @@ module WEBrick
if @config[:Port] == 0
@config[:Port] = @listeners[0].addr[1]
end
- @shutdown_pipe_r, @shutdown_pipe_w = IO.pipe
+ @shutdown_pipe = IO.pipe
end
end
@@ -164,13 +164,15 @@ module WEBrick
"#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
call_callback(:StartCallback)
+ shutdown_pipe = @shutdown_pipe
+
thgroup = ThreadGroup.new
@status = :Running
begin
while @status == :Running
begin
- if svrs = IO.select([@shutdown_pipe_r, *@listeners], nil, nil, 2.0)
- if svrs[0].include? @shutdown_pipe_r
+ if svrs = IO.select([shutdown_pipe[0], *@listeners], nil, nil, 2.0)
+ if svrs[0].include? shutdown_pipe[0]
break
end
svrs[0].each{|svr|
@@ -197,7 +199,7 @@ module WEBrick
end
end
ensure
- cleanup_shutdown_pipe
+ cleanup_shutdown_pipe(shutdown_pipe)
cleanup_listener
@status = :Shutdown
@logger.info "going to shutdown ..."
@@ -225,11 +227,13 @@ module WEBrick
def shutdown
stop
- shutdown_pipe_w = @shutdown_pipe_w # another thread may modify @shutdown_pipe_w.
- if shutdown_pipe_w && !shutdown_pipe_w.closed?
- begin
- shutdown_pipe_w.close
- rescue IOError # closed by another thread.
+ shutdown_pipe = @shutdown_pipe # another thread may modify @shutdown_pipe.
+ if shutdown_pipe
+ if !shutdown_pipe[1].closed?
+ begin
+ shutdown_pipe[1].close
+ rescue IOError # closed by another thread.
+ end
end
end
end
@@ -317,13 +321,16 @@ module WEBrick
end
end
- def cleanup_shutdown_pipe
- @shutdown_pipe_r.close
- begin
- @shutdown_pipe_w.close
- rescue IOError # another thread closed @shutdown_pipe_w.
- end
- @shutdown_pipe_r = @shutdown_pipe_w = nil
+ def cleanup_shutdown_pipe(shutdown_pipe)
+ @shutdown_pipe = nil
+ shutdown_pipe.each {|io|
+ if !io.closed?
+ begin
+ io.close
+ rescue IOError # another thread closed io.
+ end
+ end
+ }
end
def cleanup_listener