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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-11-10 11:05:00 +00:00
Родитель fd9f6bde95
Коммит 33bb38a644
4 изменённых файлов: 45 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Mon Nov 10 20:04:16 2014 Tanaka Akira <akr@fsij.org>
* lib/webrick/server.rb: Setup shutdown pipe in listen method.
Mon Nov 10 19:37:09 2014 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c, include/win32/win32.h (rb_w32_set_nonblock): new

Просмотреть файл

@ -115,7 +115,6 @@ module WEBrick
if @config[:Port] == 0
@config[:Port] = @listeners[0].addr[1]
end
@shutdown_pipe = IO.pipe
end
end
@ -132,6 +131,7 @@ module WEBrick
def listen(address, port)
@listeners += Utils::create_listeners(address, port, @logger)
setup_shutdown_pipe
end
##
@ -321,6 +321,13 @@ module WEBrick
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|

Просмотреть файл

@ -162,6 +162,7 @@ module WEBrick
}
end
@listeners += listeners
setup_shutdown_pipe
end
##

Просмотреть файл

@ -96,4 +96,36 @@ class TestWEBrickServer < Test::Unit::TestCase
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