diff options
author | seki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-16 14:31:55 +0000 |
---|---|---|
committer | seki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-16 14:31:55 +0000 |
commit | 6eb36185426a581b708060f41b11c8a2ef1e1532 (patch) | |
tree | 949d86cea73d5580c34b45fc077592bf285a66c3 /lib | |
parent | 7f2c9e86d8bafb38da2371b6a4ed2e8804a2833c (diff) | |
download | ruby-6eb36185426a581b708060f41b11c8a2ef1e1532.tar.gz ruby-6eb36185426a581b708060f41b11c8a2ef1e1532.tar.xz ruby-6eb36185426a581b708060f41b11c8a2ef1e1532.zip |
backported from CVS_HEAD
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/drb/drb.rb | 30 | ||||
-rw-r--r-- | lib/drb/ssl.rb | 4 |
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index f3ed778da..eba58e358 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -815,14 +815,40 @@ module DRb self.new(uri, soc, config) end + def self.getservername + host = Socket::gethostname + begin + Socket::gethostbyname(host)[0] + rescue + host + end + end + + def self.open_server_inaddr_any(host, port) + infos = Socket::getaddrinfo(host, nil, + Socket::AF_UNSPEC, + Socket::SOCK_STREAM, + 0, + Socket::AI_PASSIVE) + family = infos.collect { |af, *_| af }.uniq + case family + when ['AF_INET'] + return TCPServer.open('0.0.0.0', port) + when ['AF_INET6'] + return TCPServer.open('::', port) + else + return TCPServer.open(port) + end + end + # Open a server listening for connections at +uri+ using # configuration +config+. def self.open_server(uri, config) uri = 'druby://:0' unless uri host, port, opt = parse_uri(uri) if host.size == 0 - soc = TCPServer.open(port) - host = Socket.gethostname + host = getservername + soc = open_server_inaddr_any(host, port) else soc = TCPServer.open(host, port) end diff --git a/lib/drb/ssl.rb b/lib/drb/ssl.rb index 1a454a59c..a1395351f 100644 --- a/lib/drb/ssl.rb +++ b/lib/drb/ssl.rb @@ -136,8 +136,8 @@ module DRb uri = 'drbssl://:0' unless uri host, port, opt = parse_uri(uri) if host.size == 0 - soc = TCPServer.open(port) - host = Socket.gethostname + host = getservername + soc = open_server_inaddr_any(host, port) else soc = TCPServer.open(host, port) end |