Class: Async::IO::HostEndpoint
- Defined in:
 - lib/async/io/host_endpoint.rb
 
Instance Attribute Summary
Attributes inherited from Endpoint
Instance Method Summary collapse
- #address ⇒ Object
 - 
  
    
      #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, #bound, composite, #connected, each, #linger, #local_address, parse, #reuse_address, #reuse_port, socket, ssl, tcp, #timeout, try_convert, udp, unix, #with
Constructor Details
#initialize(specification, **options) ⇒ HostEndpoint
Returns a new instance of HostEndpoint.
      13 14 15 16 17  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 13 def initialize(specification, **) super(**) @specification = specification end  | 
  
Instance Method Details
#address ⇒ Object
      25 26 27  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 25 def address @specification end  | 
  
#bind {|Socket| ... } ⇒ Array<Socket>
Invokes the given block for every address which can be bound to.
      64 65 66 67 68  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 64 def bind(&block) Addrinfo.foreach(*@specification).map 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.
      37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 37 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 {|AddressEndpoint| ... } ⇒ Object
      71 72 73 74 75 76 77  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 71 def each return to_enum unless block_given? Addrinfo.foreach(*@specification) do |address| yield AddressEndpoint.new(address, **@options) end end  | 
  
#hostname ⇒ Object
      29 30 31  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 29 def hostname @specification.first end  | 
  
#to_s ⇒ Object
      19 20 21 22 23  | 
    
      # File 'lib/async/io/host_endpoint.rb', line 19 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  |