[前][次][番号順一覧][スレッド一覧]

ruby-changes:36281

From: akr <ko1@a...>
Date: Mon, 10 Nov 2014 20:05:16 +0900 (JST)
Subject: [ruby-changes:36281] akr:r48362 (trunk): * lib/webrick/server.rb: Setup shutdown pipe in listen method.

akr	2014-11-10 20:05:00 +0900 (Mon, 10 Nov 2014)

  New Revision: 48362

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48362

  Log:
    * lib/webrick/server.rb: Setup shutdown pipe in listen method.

  Modified files:
    trunk/ChangeLog
    trunk/lib/webrick/server.rb
    trunk/lib/webrick/ssl.rb
    trunk/test/webrick/test_server.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48361)
+++ ChangeLog	(revision 48362)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Nov 10 20:04:16 2014  Tanaka Akira  <akr@f...>
+
+	* lib/webrick/server.rb: Setup shutdown pipe in listen method.
+
 Mon Nov 10 19:37:09 2014  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c, include/win32/win32.h (rb_w32_set_nonblock): new
Index: lib/webrick/ssl.rb
===================================================================
--- lib/webrick/ssl.rb	(revision 48361)
+++ lib/webrick/ssl.rb	(revision 48362)
@@ -162,6 +162,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/ssl.rb#L162
         }
       end
       @listeners += listeners
+      setup_shutdown_pipe
     end
 
     ##
Index: lib/webrick/server.rb
===================================================================
--- lib/webrick/server.rb	(revision 48361)
+++ lib/webrick/server.rb	(revision 48362)
@@ -115,7 +115,6 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L115
         if @config[:Port] == 0
           @config[:Port] = @listeners[0].addr[1]
         end
-        @shutdown_pipe = IO.pipe
       end
     end
 
@@ -132,6 +131,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L131
 
     def listen(address, port)
       @listeners += Utils::create_listeners(address, port, @logger)
+      setup_shutdown_pipe
     end
 
     ##
@@ -321,6 +321,13 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L321
       end
     end
 
+    def setup_shutdown_pipe
+      if !@shutdown_pipe
+        @shutdown_pipe = IO.pipe
+      end
+      @shutdown_pipe
+    end
+
     def cleanup_shutdown_pipe(shutdown_pipe)
       @shutdown_pipe = nil
       shutdown_pipe.each {|io|
Index: test/webrick/test_server.rb
===================================================================
--- test/webrick/test_server.rb	(revision 48361)
+++ test/webrick/test_server.rb	(revision 48362)
@@ -96,4 +96,36 @@ class TestWEBrickServer < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/webrick/test_server.rb#L96
       w.close
     end
   end
+
+  def test_restart
+    address = '127.0.0.1'
+    port = 0
+    log = []
+    config = {
+      :BindAddress => address,
+      :Port => port,
+      :Logger => WEBrick::Log.new(log, WEBrick::BasicLog::WARN),
+    }
+    server = Echo.new(config)
+    client_proc = lambda {|str|
+      begin
+        ret = server.listeners.first.connect_address.connect {|s|
+          s.write(str)
+          s.close_write
+          s.read
+        }
+        assert_equal(str, ret)
+      ensure
+        server.shutdown
+      end
+    }
+    server_thread = Thread.new { server.start }
+    client_thread = Thread.new { client_proc.call("a") }
+    assert_join_threads([client_thread, server_thread])
+    server.listen(address, port)
+    server_thread = Thread.new { server.start }
+    client_thread = Thread.new { client_proc.call("b") }
+    assert_join_threads([client_thread, server_thread])
+    assert_equal([], log)
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]