123456789_123456789_123456789_123456789_123456789_

Class: Socket::HostnameResolutionStore

Relationships & Source Files
Inherits: Object
Defined in: ext/socket/lib/socket.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(family_names) ⇒ HostnameResolutionStore

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1045

def initialize(family_names)
  @family_names = family_names
  @addrinfo_dict = {}
  @error_dict = {}
  @last_family = nil
end

Instance Attribute Details

#any_addrinfos?Boolean (readonly)

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1083

def any_addrinfos?
  !empty_addrinfos?
end

#any_unresolved_family?Boolean (readonly)

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1099

def any_unresolved_family?
  !resolved_all_families?
end

#empty_addrinfos?Boolean (readonly)

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1079

def empty_addrinfos?
  @addrinfo_dict.all? { |_, addrinfos| addrinfos.empty? }
end

#resolved_all_families?Boolean (readonly)

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1095

def resolved_all_families?
  (@family_names - @addrinfo_dict.keys).empty?
end

Instance Method Details

#add_error(family_name, error)

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1056

def add_error(family_name, error)
  @addrinfo_dict[family_name] = []
  @error_dict[family_name] = error
end

#add_resolved(family_name, addrinfos)

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1052

def add_resolved(family_name, addrinfos)
  @addrinfo_dict[family_name] = addrinfos
end

#get_addrinfo

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1061

def get_addrinfo
  precedences =
    case @last_family
    when :ipv4, nil then PRIORITY_ON_V6
    when :ipv6      then PRIORITY_ON_V4
    end

  precedences.each do |family_name|
    addrinfo = @addrinfo_dict[family_name]&.shift
    next unless addrinfo

    @last_family = family_name
    return addrinfo
  end

  nil
end

#resolved?(family) ⇒ Boolean

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1087

def resolved?(family)
  @addrinfo_dict.has_key? family
end

#resolved_successfully?(family) ⇒ Boolean

[ GitHub ]

  
# File 'ext/socket/lib/socket.rb', line 1091

def resolved_successfully?(family)
  resolved?(family) && !!@error_dict[family]
end