Class: IO::Endpoint::AddressEndpoint
- Defined in:
- lib/io/endpoint/address_endpoint.rb
Overview
Represents an endpoint for a specific network address.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
- #The network address for this endpoint.(networkaddress) ⇒ Object readonly
Attributes inherited from Generic
Instance Method Summary collapse
-
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind a socket to the given address.
-
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connects a socket to the given address.
-
#initialize(address, **options) ⇒ AddressEndpoint
constructor
Initialize a new address endpoint.
-
#inspect ⇒ Object
Get a detailed string representation of the endpoint.
-
#to_s ⇒ Object
Get a string representation of the endpoint.
Methods inherited from Generic
#accept, #bound, #connected, #each, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #with, #wrapper
Constructor Details
#initialize(address, **options) ⇒ AddressEndpoint
Initialize a new address endpoint.
17 18 19 20 21 |
# File 'lib/io/endpoint/address_endpoint.rb', line 17 def initialize(address, **) super(**) @address = address end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
43 44 45 |
# File 'lib/io/endpoint/address_endpoint.rb', line 43 def address @address end |
#The network address for this endpoint.(networkaddress) ⇒ Object (readonly)
43 |
# File 'lib/io/endpoint/address_endpoint.rb', line 43 attr :address |
Instance Method Details
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
49 50 51 |
# File 'lib/io/endpoint/address_endpoint.rb', line 49 def bind(wrapper = self.wrapper, &block) [wrapper.bind(@address, **@options, &block)] end |
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
55 56 57 |
# File 'lib/io/endpoint/address_endpoint.rb', line 55 def connect(wrapper = self.wrapper, &block) wrapper.connect(@address, **@options, &block) end |
#inspect ⇒ Object
Get a detailed string representation of the endpoint.
38 39 40 |
# File 'lib/io/endpoint/address_endpoint.rb', line 38 def inspect "\#<#{self.class} address=#{@address.inspect}>" end |
#to_s ⇒ Object
Get a string representation of the endpoint.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/io/endpoint/address_endpoint.rb', line 25 def to_s case @address.afamily when Socket::AF_INET "inet:#{@address.inspect_sockaddr}" when Socket::AF_INET6 "inet6:#{@address.inspect_sockaddr}" else "address:#{@address.inspect_sockaddr}" end end |