lib/dripdrop/node.rb in dripdrop-0.7.1 vs lib/dripdrop/node.rb in dripdrop-0.8.0
- old
+ new
@@ -1,18 +1,24 @@
require 'rubygems'
require 'ffi-rzmq'
require 'zmqmachine'
require 'eventmachine'
require 'uri'
+require 'resolv'
+require 'ipaddr'
require 'dripdrop/message'
require 'dripdrop/node/nodelet'
require 'dripdrop/handlers/base'
require 'dripdrop/handlers/zeromq'
require 'dripdrop/handlers/websockets'
require 'dripdrop/handlers/http'
+if defined?(Fiber)
+ require 'em-resolv-replace'
+end
+
class DripDrop
class Node
attr_reader :zm_reactor, :routing, :nodelets
attr_accessor :debug
@@ -274,10 +280,15 @@
private
def zmq_handler(klass, zm_sock_type, address, socket_ctype, opts={})
addr_uri = URI.parse(address)
- zm_addr = ZM::Address.new(addr_uri.host,addr_uri.port.to_i,addr_uri.scheme.to_sym)
+
+ host = Resolv.getaddresses(addr_uri.host).first
+ host_addr = Resolv.getaddresses('localhost').map {|a| IPAddr.new(a)}.find {|a| a.ipv4?}
+ host_str = host_addr.ipv6? ? "[#{host_addr.to_s}]" : host_addr.to_s
+
+ zm_addr = ZM::Address.new(host_str,addr_uri.port.to_i,addr_uri.scheme.to_sym)
h_opts = handler_opts_given(opts)
handler = klass.new(zm_addr,@zm_reactor,socket_ctype,h_opts)
@zm_reactor.send(zm_sock_type,handler)
handler
end