diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-14 02:20:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-14 02:20:16 +0000 |
commit | 77cde58d394b01c7b5f1ab5078d18e04373065db (patch) | |
tree | 81e9808ab3af8f3c7760682c32cbf91fe06453f7 | |
parent | f162f2073be0ccad316681841805844f7f0b4b64 (diff) | |
download | ruby-77cde58d394b01c7b5f1ab5078d18e04373065db.tar.gz |
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
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | lib/webrick/server.rb | 33 | ||||
-rw-r--r-- | test/webrick/test_server.rb | 4 |
3 files changed, 34 insertions, 11 deletions
@@ -1,3 +1,11 @@ +Tue Jul 14 11:20:13 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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. + Mon Jul 13 23:58:08 2015 Stefano Tortarolo <stefano.tortarolo@gmail.com> * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#do_CONNECT): diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index 5ada88ac73..1d87cdae70 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? diff --git a/test/webrick/test_server.rb b/test/webrick/test_server.rb index 37b1dd50ca..1a720361cc 100644 --- a/test/webrick/test_server.rb +++ b/test/webrick/test_server.rb @@ -137,8 +137,12 @@ class TestWEBrickServer < Test::Unit::TestCase flunk "unexpected log: #{msg.inspect}" end end + client_thread = nil + wakeup = -> {client_thread.wakeup} warn_flunk = WEBrick::Log.new(log, WEBrick::BasicLog::WARN) server = WEBrick::HTTPServer.new( + :StartCallback => wakeup, + :StopCallback => wakeup, :BindAddress => '0.0.0.0', :Port => 0, :Logger => warn_flunk) |