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, #each, each, #hostname, #linger, #local_address, parse, #reuse_address, #reuse_port, socket, ssl, tcp, #timeout, try_convert, udp, unix, #with
Constructor Details
permalink #initialize(path, type, **options) ⇒ UNIXEndpoint
Returns a new instance of UNIXEndpoint.
29 30 31 32 33 34 |
# File 'lib/async/io/unix_endpoint.rb', line 29 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
permalink #path ⇒ Object (readonly)
Returns the value of attribute path.
40 41 42 |
# File 'lib/async/io/unix_endpoint.rb', line 40 def path @path end |
Instance Method Details
permalink #bind(&block) ⇒ Object
[View source]
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/async/io/unix_endpoint.rb', line 50 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.exist?(@path) File.unlink(@path) retry else raise end end |
permalink #bound? ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/async/io/unix_endpoint.rb', line 42 def bound? self.connect do return true end rescue Errno::ECONNREFUSED return false end |
permalink #to_s ⇒ Object
[View source]
36 37 38 |
# File 'lib/async/io/unix_endpoint.rb', line 36 def to_s "\#<#{self.class} #{@path.inspect}>" end |