From 51f7bfbb35db28f0ebdbd3e7adc28ff0e2a30b1b Mon Sep 17 00:00:00 2001 From: gotoyuzo Date: Wed, 23 Mar 2005 19:08:03 +0000 Subject: * lib/webrick/utils.rb (WEBrick::Utils.create_listeners): - should raise ArgumentError if no port is specified. - even if the specified port is 0, all TCPServers should be initialized with the port given to the first one. * lib/webrick/server.rb (WEBrick::GenericServer#initialize): if :Port parameter is 0, it should be updated with the port number which ectually listened. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ lib/webrick/server.rb | 3 +++ lib/webrick/utils.rb | 8 ++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17bbf0b94..01cc50704 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Thu Mar 24 03:57:48 2005 GOTOU Yuuzou + + * lib/webrick/utils.rb (WEBrick::Utils.create_listeners): + - should raise ArgumentError if no port is specified. + - even if the specified port is 0, all TCPServers should be + initialized with the port given to the first one. + + * lib/webrick/server.rb (WEBrick::GenericServer#initialize): if :Port + parameter is 0, it should be updated with the port number which + ectually listened. + Wed Mar 23 00:35:10 2005 Shugo Maeda * test/ruby/test_settracefunc.rb (test_event): added tests for diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index 87a33ffaa..46575734c 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -61,6 +61,9 @@ module WEBrick warn(":Listen option is deprecated; use GenericServer#listen") end listen(@config[:BindAddress], @config[:Port]) + if @config[:Port] == 0 + @config[:Port] = @listeners[0].addr[1] + end end end diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index 41b54271c..7283704c1 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -49,6 +49,9 @@ module WEBrick module_function :getservername def create_listeners(address, port, logger=nil) + unless port + raise ArgumentError, "must specify port" + end res = Socket::getaddrinfo(address, port, Socket::AF_UNSPEC, # address family Socket::SOCK_STREAM, # socket type @@ -58,8 +61,9 @@ module WEBrick sockets = [] res.each{|ai| begin - logger.debug("TCPServer.new(#{ai[3]}, #{ai[1]})") if logger - sock = TCPServer.new(ai[3], ai[1]) + logger.debug("TCPServer.new(#{ai[3]}, #{port})") if logger + sock = TCPServer.new(ai[3], port) + port = sock.addr[1] if port == 0 Utils::set_close_on_exec(sock) sockets << sock rescue => ex -- cgit