mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									f162f2073b
								
							
						
					
					
						commit
						77cde58d39
					
				
					 3 changed files with 34 additions and 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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue