Class: IO::Endpoint::ConnectedEndpoint
- Defined in:
- lib/io/endpoint/connected_endpoint.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Attributes inherited from Generic
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #connect(wrapper = self.wrapper, &block) ⇒ Object
-
#initialize(endpoint, socket, **options) ⇒ ConnectedEndpoint
constructor
A new instance of ConnectedEndpoint.
- #inspect ⇒ Object
-
#local_address_endpoint(**options) ⇒ Object
A endpoint for the local end of the bound socket.
-
#remote_address_endpoint(**options) ⇒ Object
A endpoint for the remote end of the bound socket.
- #to_s ⇒ Object
Methods inherited from Generic
#accept, #bind, #bound, #connected, #each, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #with, #wrapper
Constructor Details
#initialize(endpoint, socket, **options) ⇒ ConnectedEndpoint
Returns a new instance of ConnectedEndpoint.
22 23 24 25 26 27 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 22 def initialize(endpoint, socket, **) super(**) @endpoint = endpoint @socket = socket end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
29 30 31 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 29 def endpoint @endpoint end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
30 31 32 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 30 def socket @socket end |
Class Method Details
.connected(endpoint, close_on_exec: false) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 14 def self.connected(endpoint, close_on_exec: false) socket = endpoint.connect socket.close_on_exec = close_on_exec return self.new(endpoint, socket, **endpoint.) end |
Instance Method Details
#close ⇒ Object
52 53 54 55 56 57 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 52 def close if @socket @socket.close @socket = nil end end |
#connect(wrapper = self.wrapper, &block) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 44 def connect(wrapper = self.wrapper, &block) if block_given? yield @socket else return @socket.dup end end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 63 def inspect "\#<#{self.class} #{@socket} connected for #{@endpoint}>" end |
#local_address_endpoint(**options) ⇒ Object
A endpoint for the local end of the bound socket.
34 35 36 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 34 def local_address_endpoint(**) AddressEndpoint.new(socket.to_io.local_address, **) end |
#remote_address_endpoint(**options) ⇒ Object
A endpoint for the remote end of the bound socket.
40 41 42 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 40 def remote_address_endpoint(**) AddressEndpoint.new(socket.to_io.remote_address, **) end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 59 def to_s "connected:#{@endpoint}" end |