summaryrefslogtreecommitdiff
path: root/lib/webrick/utils.rb
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-19 06:00:36 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-19 06:00:36 +0000
commit65652ecdb5145fae92e3c86611a4425a476da6ec (patch)
treeeedc2d207ffde1876c9d7271f8492741ee065584 /lib/webrick/utils.rb
parent90e010abb9efeaaf706c363af31beedf65c8be3b (diff)
* lib/webrick/ssl.rb: new file; SSL/TLS enhancement for GenericServer.
* lib/webrick/https.rb: SSLSocket handling is moved to webrick/ssl.rb. * lib/webrick/compat.rb (File::fnmatch): remove old migration code. * lib/webrick/httpserver.rb (HTTPServer#run): ditto. * lib/webrick/server.rb (GenericServer#listen): the body of this method is pull out as Utils::create_lisnteners. * lib/webrick/utils.rb (Utils::create_lisnteners): new method. * lib/webrick/server.rb (GenericServer#start): should not through unknown errors. and refine comments. * ext/openssl/lib/openssl/ssl.rb (SSLServer#accept): should close socket if SSLSocket raises error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/utils.rb')
-rw-r--r--lib/webrick/utils.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index 646880d655..d371f4989f 100644
--- a/lib/webrick/utils.rb
+++ b/lib/webrick/utils.rb
@@ -48,6 +48,30 @@ module WEBrick
end
module_function :getservername
+ def create_listeners(address, port, logger=nil)
+ res = Socket::getaddrinfo(address, port,
+ Socket::AF_UNSPEC, # address family
+ Socket::SOCK_STREAM, # socket type
+ 0, # protocol
+ Socket::AI_PASSIVE) # flag
+ last_error = nil
+ sockets = []
+ res.each{|ai|
+ begin
+ logger.debug("TCPServer.new(#{ai[3]}, #{ai[1]})") if logger
+ sock = TCPServer.new(ai[3], ai[1])
+ Utils::set_close_on_exec(sock)
+ sockets << sock
+ rescue => ex
+ logger.warn("TCPServer Error: #{ex}") if logger
+ last_error = ex
+ end
+ }
+ raise last_error if sockets.empty?
+ return sockets
+ end
+ module_function :create_listeners
+
RAND_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"0123456789" +
"abcdefghijklmnopqrstuvwxyz"