summaryrefslogtreecommitdiff
path: root/lib/webrick/server.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-14 02:20:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-14 02:20:16 +0000
commit77cde58d394b01c7b5f1ab5078d18e04373065db (patch)
tree81e9808ab3af8f3c7760682c32cbf91fe06453f7 /lib/webrick/server.rb
parentf162f2073be0ccad316681841805844f7f0b4b64 (diff)
webrick/server.rb: stop immediately
* lib/webrick/server.rb (WEBrick::GenericServer#start): flush shutdown pipe. * lib/webrick/server.rb (WEBrick::GenericServer#stop): request the server to stop immediately by sending data via shutdown pipe. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/server.rb')
-rw-r--r--lib/webrick/server.rb33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 5ada88a..1d87cda 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -172,8 +172,13 @@ module WEBrick
begin
while @status == :Running
begin
- if svrs = IO.select([shutdown_pipe[0], *@listeners], nil, nil, 2.0)
- if svrs[0].include? shutdown_pipe[0]
+ sp = shutdown_pipe[0]
+ if svrs = IO.select([sp, *@listeners], nil, nil, 2.0)
+ if svrs[0].include? sp
+ # swallow shutdown pipe
+ buf = String.new
+ nil while String ===
+ sp.read_nonblock([sp.nread, 8].max, buf, exception: false)
break
end
svrs[0].each{|svr|
@@ -221,6 +226,8 @@ module WEBrick
if @status == :Running
@status = :Shutdown
end
+
+ alarm_shutdown_pipe {|f| f.write_nonblock("\0")}
end
##
@@ -230,15 +237,7 @@ module WEBrick
def shutdown
stop
- 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
+ alarm_shutdown_pipe {|f| f.close}
end
##
@@ -343,6 +342,18 @@ module WEBrick
}
end
+ def alarm_shutdown_pipe
+ _, pipe = @shutdown_pipe # another thread may modify @shutdown_pipe.
+ if pipe
+ if !pipe.closed?
+ begin
+ yield pipe
+ rescue IOError # closed by another thread.
+ end
+ end
+ end
+ end
+
def cleanup_listener
@listeners.each{|s|
if @logger.debug?