Class: Async::IO::HostEndpoint
- Defined in:
- lib/async/io/host_endpoint.rb
Instance Attribute Summary
Attributes inherited from Endpoint
Instance Method Summary collapse
-
#bind {|Socket| ... } ⇒ Array<Socket>
Invokes the given block for every address which can be bound to.
-
#connect {|Socket| ... } ⇒ Socket
Try to connect to the given host by connecting to each address in sequence until a connection is made.
- #each {|AddressEndpoint| ... } ⇒ Object
- #hostname ⇒ Object
-
#initialize(specification, **options) ⇒ HostEndpoint
constructor
A new instance of HostEndpoint.
- #to_s ⇒ Object
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, **) super(**) @specification = specification end |
Instance Method Details
#bind {|Socket| ... } ⇒ Array<Socket>
Invokes the given block for every address which can be bound to.
61 62 63 64 65 |
# File 'lib/async/io/host_endpoint.rb', line 61 def bind(&block) Addrinfo.foreach(*@specification).collect do |address| Socket.bind(address, **@options, &block) end end |
#connect {|Socket| ... } ⇒ Socket
Try to connect to the given host by connecting to each address in sequence until a connection is made.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/async/io/host_endpoint.rb', line 44 def connect(&block) last_error = nil Addrinfo.foreach(*@specification) do |address| begin return Socket.connect(address, **@options, &block) rescue last_error = $! end end raise last_error end |
#each {|AddressEndpoint| ... } ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/async/io/host_endpoint.rb', line 68 def each return to_enum unless block_given? Addrinfo.foreach(*@specification) do |address| yield AddressEndpoint.new(address, **@options) end end |
#hostname ⇒ Object
36 37 38 |
# File 'lib/async/io/host_endpoint.rb', line 36 def hostname @specification.first end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/async/io/host_endpoint.rb', line 32 def to_s "\#<#{self.class} #{@specification.inspect}>" end |