Class: IO::Endpoint::UNIXEndpoint
- Inherits:
-
AddressEndpoint
- Object
- Generic
- AddressEndpoint
- IO::Endpoint::UNIXEndpoint
- Defined in:
- lib/io/endpoint/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 Generic
Instance Method Summary collapse
- #bind(&block) ⇒ Object
- #bound? ⇒ Boolean
-
#initialize(path, type = Socket::SOCK_STREAM, **options) ⇒ UNIXEndpoint
constructor
A new instance of UNIXEndpoint.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods inherited from AddressEndpoint
Methods inherited from Generic
#accept, #bound, #connect, #connected, #each, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #with, #wrapper
Constructor Details
#initialize(path, type = Socket::SOCK_STREAM, **options) ⇒ UNIXEndpoint
Returns a new instance of UNIXEndpoint.
11 12 13 14 15 16 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 11 def initialize(path, type = Socket::SOCK_STREAM, **) # 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.
26 27 28 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 26 def path @path end |
Instance Method Details
#bind(&block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 38 def bind(&block) super 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
28 29 30 31 32 33 34 35 36 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 28 def bound? self.connect do return true end rescue Errno::ECONNREFUSED return false rescue Errno::ENOENT return false end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 22 def inspect "\#<#{self.class} path=#{@path.inspect}>" end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 18 def to_s "unix:#{@path}" end |