class Async::IO::HostEndpoint

Public Class Methods

new(specification, **options) click to toggle source
Calls superclass method Async::IO::Endpoint::new
# File lib/async/io/host_endpoint.rb, line 28
def initialize(specification, **options)
        super(**options)
        
        @specification = specification
end

Public Instance Methods

address() click to toggle source
# File lib/async/io/host_endpoint.rb, line 40
def address
        @specification
end
bind(&block) click to toggle source

Invokes the given block for every address which can be bound to. @yield [Socket] the bound socket @return [Array<Socket>] an array of bound sockets

# File lib/async/io/host_endpoint.rb, line 79
def bind(&block)
        Addrinfo.foreach(*@specification).map do |address|
                Socket.bind(address, **@options, &block)
        end
end
connect() { |wrapper, task| ... } click to toggle source

Try to connect to the given host by connecting to each address in sequence until a connection is made. @yield [Socket] the socket which is being connected, may be invoked more than once @return [Socket] the connected socket @raise if no connection could complete successfully

# File lib/async/io/host_endpoint.rb, line 52
def connect
        last_error = nil
        
        task = Task.current
        
        Addrinfo.foreach(*@specification) do |address|
                begin
                        wrapper = Socket.connect(address, **@options, task: task)
                rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::EAGAIN
                        last_error = $!
                else
                        return wrapper unless block_given?
                        
                        begin
                                return yield wrapper, task
                        ensure
                                wrapper.close
                        end
                end
        end
        
        raise last_error
end
each() { |address_endpoint(address, **options)| ... } click to toggle source

@yield [AddressEndpoint] address endpoints by resolving the given host specification

# File lib/async/io/host_endpoint.rb, line 86
def each
        return to_enum unless block_given?
        
        Addrinfo.foreach(*@specification) do |address|
                yield AddressEndpoint.new(address, **@options)
        end
end
hostname() click to toggle source
# File lib/async/io/host_endpoint.rb, line 44
def hostname
        @specification.first
end
to_s() click to toggle source
# File lib/async/io/host_endpoint.rb, line 34
def to_s
        nodename, service, family, socktype, protocol, flags = @specification
        
        "\#<#{self.class} name=#{nodename.inspect} service=#{service.inspect} family=#{family.inspect} type=#{socktype.inspect} protocol=#{protocol.inspect} flags=#{flags.inspect}>"
end