class Addrinfo

Public Class Methods

parse(*args) click to toggle source
# File lib/gxg/gxg_augmented.rb, line 1752
def self.parse(*args)
  # Attempts to create an address object for the given URI/URL
  address = nil
  if args[0].is_a?(::URI::Generic)
    raw_uri = args[0]
  else
    raw_uri = ::URI::parse(*args)
  end
  #
  the_protocol = nil
  the_port = nil
  service_details = ::GxG::SYSTEM.service_ports_search({:scheme => raw_uri.scheme()})
  if service_details.keys().size > 0
    service_details = service_details[(service_details.keys()[0])]
    if service_details[:usage_preference]
      if service_details[:usage][(service_details[:usage_preference])].is_a?(::Array)
        the_port = service_details[:usage][(service_details[:usage_preference])][0]
        if the_port.is_a?(::Range)
          the_protocol = (service_details[:usage_preference])
          the_port = the_port.first
        end
      end
    else
      if service_details[:usage][(service_details[:usage].keys()[0])].is_a?(::Array)
        the_port = service_details[:usage][(service_details[:usage].keys()[0])][0]
        if the_port.is_a?(::Range)
          the_protocol = (service_details[:usage].keys()[0])
          the_port = the_port.first
        end
      end
    end
  end
  unless the_protocol
    the_protocol = raw_uri.scheme().to_sym
  end
  #
  case the_protocol
  when :inproc
    #
  when :ipc
    # LATER: Anything to be done for IPC stuff here??? (Not available on winderz)
  when :pgm
    #
  when :epgm
    #
  when :unix, :socket
    if (raw_uri.hostname().to_s.size == 0)
      # Unix socket
      address = ::Addrinfo.unix(raw_uri.path())
    else
      # tcp used by default for ipc
      if raw_uri.hostname().to_s.size > 0
        address = ::Addrinfo.tcp(raw_uri.hostname(), (raw_uri.port() || raw_uri.default_port() || the_port || "*"))
      else
        address = ::Addrinfo.tcp("0.0.0.0", (raw_uri.port() || raw_uri.default_port() || the_port || "*"))
      end
    end
  when :tcp, :tcp4, :tcp6
    if raw_uri.hostname().to_s.size > 0
      address = ::Addrinfo.tcp(raw_uri.hostname(), (raw_uri.port() || raw_uri.default_port() || the_port || "*"))
    else
      address = ::Addrinfo.tcp("0.0.0.0", (raw_uri.port() || raw_uri.default_port() || the_port || "*"))
    end
  when :udp, :udp4, :udp6
    if raw_uri.hostname().to_s.size > 0
      address = ::Addrinfo.udp(raw_uri.hostname(), (raw_uri.port() || raw_uri.default_port() || the_port || "*"))
    else
      address = ::Addrinfo.udp("0.0.0.0", (raw_uri.port() || raw_uri.default_port() || the_port || "*"))
    end
  end
  #
  address
end

Public Instance Methods

uri_info() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 1826
def uri_info()
  result = nil
  if self.ip?()
    case self.protocol
    when ::Socket::IPPROTO_TCP
      result = ::URI::parse("tcp://#{self.ip_address()}:#{(self.ip_port() || '*')}")
    when ::Socket::IPPROTO_UDP
      result = ::URI::parse("udp://#{self.ip_address()}:#{(self.ip_port() || '*')}")
    end
  else
    if self.unix?()
      result = ::URI::parse("unix://#{self.unix_path()}")
    else
      # not sure what to do here
    end
  end
  result
end