Class: IO::Endpoint::ConnectedEndpoint
- Defined in:
- lib/io/endpoint/connected_endpoint.rb
Overview
Represents an endpoint that has been connected to a socket.
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
- #The original endpoint that was connected.(originalendpointthatwasconnected.) ⇒ Object readonly
Attributes inherited from Generic
Class Method Summary collapse
-
.connected(endpoint, close_on_exec: false) ⇒ Object
Create a connected endpoint from an existing endpoint.
Instance Method Summary collapse
-
#close ⇒ Object
Close the connected socket.
-
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connect using the already connected socket.
-
#initialize(endpoint, socket, **options) ⇒ ConnectedEndpoint
constructor
Initialize a new connected endpoint.
-
#inspect ⇒ Object
Get a detailed string representation of the connected endpoint.
-
#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.
- #The socket that was connected.=(socketthatwasconnected. = (value)) ⇒ Object
-
#to_s ⇒ Object
Get a string representation of the connected endpoint.
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
Initialize a new connected endpoint.
31 32 33 34 35 36 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 31 def initialize(endpoint, socket, **) super(**) @endpoint = endpoint @socket = socket end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
39 40 41 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 39 def endpoint @endpoint end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
41 42 43 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 41 def socket @socket end |
#The original endpoint that was connected.(originalendpointthatwasconnected.) ⇒ Object (readonly)
39 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 39 attr :endpoint |
Class Method Details
.connected(endpoint, close_on_exec: false) ⇒ Object
Create a connected endpoint from an existing endpoint.
19 20 21 22 23 24 25 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 19 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
Close the connected socket.
69 70 71 72 73 74 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 69 def close if @socket @socket.close @socket = nil end end |
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connect using the already connected socket.
60 61 62 63 64 65 66 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 60 def connect(wrapper = self.wrapper, &block) if block_given? yield @socket else return @socket.dup end end |
#inspect ⇒ Object
Get a detailed string representation of the connected endpoint.
84 85 86 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 84 def inspect "\#<#{self.class} #{@socket} connected for #{@endpoint}>" end |
#local_address_endpoint(**options) ⇒ Object
A endpoint for the local end of the bound socket.
45 46 47 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 45 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.
51 52 53 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 51 def remote_address_endpoint(**) AddressEndpoint.new(socket.to_io.remote_address, **) end |
#The socket that was connected.=(socketthatwasconnected. = (value)) ⇒ Object
41 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 41 attr :socket |
#to_s ⇒ Object
Get a string representation of the connected endpoint.
78 79 80 |
# File 'lib/io/endpoint/connected_endpoint.rb', line 78 def to_s "connected:#{@endpoint}" end |