class Socket::SelectableAddrinfos
Constants
- PRIORITY_ON_V4
- PRIORITY_ON_V6
Public Class Methods
new()
click to toggle source
# File socket/lib/socket.rb, line 977 def initialize @addrinfo_dict = {} @last_family = nil end
Public Instance Methods
add(family_name, addrinfos)
click to toggle source
# File socket/lib/socket.rb, line 982 def add(family_name, addrinfos) @addrinfo_dict[family_name] = addrinfos end
any?()
click to toggle source
# File socket/lib/socket.rb, line 1011 def any? !empty? end
empty?()
click to toggle source
# File socket/lib/socket.rb, line 1007 def empty? @addrinfo_dict.all? { |_, addrinfos| addrinfos.empty? } end
get()
click to toggle source
# File socket/lib/socket.rb, line 986 def get return nil if empty? if @addrinfo_dict.size == 1 @addrinfo_dict.each { |_, addrinfos| return addrinfos.shift } end 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 end