From 0b05f3b5f0a405b38f4953b74f647eeb03d50ad2 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 14 Jul 2015 02:20:16 +0000 Subject: 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 --- lib/webrick/server.rb | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'lib') 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? -- cgit v1.2.3