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.
- #The path to the UNIX socket.(pathtotheUNIXsocket.) ⇒ Object readonly
Attributes inherited from AddressEndpoint
#The network address for this endpoint., #address
Attributes inherited from Generic
Instance Method Summary collapse
-
#bind ⇒ Object
Bind the UNIX socket, handling stale socket files.
-
#bound? ⇒ Boolean
Check if the socket is currently bound and accepting connections.
-
#initialize(path, type = Socket::SOCK_STREAM, **options) ⇒ UNIXEndpoint
constructor
Initialize a new UNIX domain socket endpoint.
-
#inspect ⇒ Object
Get a detailed string representation of the UNIX endpoint.
-
#to_s ⇒ Object
Get a string representation of the UNIX endpoint.
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
Initialize a new UNIX domain socket endpoint.
15 16 17 18 19 20 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 15 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.
35 36 37 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 35 def path @path end |
#The path to the UNIX socket.(pathtotheUNIXsocket.) ⇒ Object (readonly)
35 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 35 attr :path |
Instance Method Details
#bind ⇒ Object
Bind the UNIX socket, handling stale socket files.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 54 def bind(...) 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
Check if the socket is currently bound and accepting connections.
39 40 41 42 43 44 45 46 47 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 39 def bound? self.connect do return true end rescue Errno::ECONNREFUSED return false rescue Errno::ENOENT return false end |
#inspect ⇒ Object
Get a detailed string representation of the UNIX endpoint.
30 31 32 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 30 def inspect "\#<#{self.class} path=#{@path.inspect}>" end |
#to_s ⇒ Object
Get a string representation of the UNIX endpoint.
24 25 26 |
# File 'lib/io/endpoint/unix_endpoint.rb', line 24 def to_s "unix:#{@path}" end |