Class: Async::IO::HostEndpoint

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/async/io/host_endpoint.rb

Instance Attribute Summary

Attributes inherited from Endpoint

#options

Instance Method Summary collapse

Methods inherited from Endpoint

#accept, each, parse, socket, ssl, tcp, try_convert, udp, unix

Constructor Details

#initialize(specification, **options) ⇒ HostEndpoint

Returns a new instance of HostEndpoint.



26
27
28
29
30
# File 'lib/async/io/host_endpoint.rb', line 26

def initialize(specification, **options)
	super(**options)
	
	@specification = specification
end

Instance Method Details

#bind(&block) ⇒ Object



54
55
56
57
58
# File 'lib/async/io/host_endpoint.rb', line 54

def bind(&block)
	Addrinfo.foreach(*@specification) do |address|
		Socket.bind(address, **@options, &block)
	end
end

#connect(&block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/async/io/host_endpoint.rb', line 40

def connect(&block)
	last_error = nil
	
	Addrinfo.foreach(*@specification).each do |address|
		begin
			return Socket.connect(address, **@options, &block)
		rescue
			last_error = $!
		end
	end
	
	raise last_error
end

#eachObject



60
61
62
63
64
65
66
# File 'lib/async/io/host_endpoint.rb', line 60

def each
	return to_enum unless block_given?
	
	Addrinfo.foreach(*@specification).each do |address|
		yield AddressEndpoint.new(address, **@options)
	end
end

#hostnameObject



36
37
38
# File 'lib/async/io/host_endpoint.rb', line 36

def hostname
	@specification.first
end

#to_sObject



32
33
34
# File 'lib/async/io/host_endpoint.rb', line 32

def to_s
	"\#<#{self.class} #{@specification.inspect}>"
end