Class: Async::IO::UNIXEndpoint
- Inherits:
 - 
      AddressEndpoint
      
        
- Object
 - Endpoint
 - AddressEndpoint
 - Async::IO::UNIXEndpoint
 
 
- Defined in:
 - lib/async/io/unix_endpoint.rb
 
Overview
This class doesn’t exert ownership over the specified unix socket and ensures exclusive access by using ‘flock` where possible.
Instance Attribute Summary collapse
- 
  
    
      #path  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute path.
 
Attributes inherited from AddressEndpoint
Attributes inherited from Endpoint
Instance Method Summary collapse
- #bind(&block) ⇒ Object
 - #bound? ⇒ Boolean
 - 
  
    
      #initialize(path, type, **options)  ⇒ UNIXEndpoint 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of UNIXEndpoint.
 - #to_s ⇒ Object
 
Methods inherited from AddressEndpoint
Methods inherited from Endpoint
#accept, #bound, composite, #connected, #each, each, #hostname, #linger, #local_address, parse, #reuse_address, #reuse_port, socket, ssl, tcp, #timeout, try_convert, udp, unix, #with
Constructor Details
#initialize(path, type, **options) ⇒ UNIXEndpoint
Returns a new instance of UNIXEndpoint.
      14 15 16 17 18 19  | 
    
      # File 'lib/async/io/unix_endpoint.rb', line 14 def initialize(path, type, **) # I wonder if we should implement chdir behaviour in here if path is longer than 104 characters. super(Address.unix(path, type), **) @path = path end  | 
  
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
      25 26 27  | 
    
      # File 'lib/async/io/unix_endpoint.rb', line 25 def path @path end  | 
  
Instance Method Details
#bind(&block) ⇒ Object
      35 36 37 38 39 40 41 42 43 44 45  | 
    
      # File 'lib/async/io/unix_endpoint.rb', line 35 def bind(&block) Socket.bind(@address, **@options, &block) rescue Errno::EADDRINUSE # If you encounter EADDRINUSE from `bind()`, you can check if the socket is actually accepting connections by attempting to `connect()` to it. If the socket is still bound by an active process, the connection will succeed. Otherwise, it should be safe to `unlink()` the path and try again. if !bound? File.unlink(@path) rescue nil retry else raise end end  | 
  
#bound? ⇒ Boolean
      27 28 29 30 31 32 33  | 
    
      # File 'lib/async/io/unix_endpoint.rb', line 27 def bound? self.connect do return true end rescue Errno::ECONNREFUSED return false end  | 
  
#to_s ⇒ Object
      21 22 23  | 
    
      # File 'lib/async/io/unix_endpoint.rb', line 21 def to_s "\#<#{self.class} #{@path.inspect}>" end  |