In message <20050320203133.GA1012 / ensemble.local>,
`Sam Roberts <sroberts / uniserve.com>' wrote:
> Is there really a case when you would want every listener to have a
> different port # assigned by the network stack? If not, maybe setting
> :Port to 0 should have the above behaviour.
I prefer nil than 0 for this behavior. It the specified port
is nil, listening port will be chosen and tried to bind until
succeed like this:
module WEBrick
class GenericServer
def listen(addr, port)
return auto_listen(addr) unless port
@listeners += Utils.create_listeners(addr, port, @logger)
end
def auto_listen(addr)
port = 65535
while port > 1023
begin
listen(addr, port)
rescue Errno::EACCES, Errno::EADDRINUSE
port -= 1
retry
end
@config[:Port] = port
return
end
end
end
end
If nobody opposes, I can make it as a default behavior of
WEBrick.
--
gotoyuzo