Class: Async::IO::HostEndpoint
Instance Method Summary
collapse
Methods inherited from Endpoint
#accept, each, parse, ssl, tcp, try_convert, udp, unix
Constructor Details
#initialize(specification, **options) ⇒ HostEndpoint
Returns a new instance of HostEndpoint.
96
97
98
99
|
# File 'lib/async/io/endpoint.rb', line 96
def initialize(specification, **options)
@specification = specification
@options = options
end
|
Instance Method Details
#bind(&block) ⇒ Object
115
116
117
118
119
|
# File 'lib/async/io/endpoint.rb', line 115
def bind(&block)
Addrinfo.foreach(*@specification) do |address|
Socket.bind(address, **@options, &block)
end
end
|
#connect(&block) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/async/io/endpoint.rb', line 101
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
|
#each ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/async/io/endpoint.rb', line 121
def each
return to_enum unless block_given?
Addrinfo.foreach(*@specification).each do |address|
yield AddressEndpoint.new(address, **@options)
end
end
|