class ConnectedEndpoint
Represents an endpoint that has been connected to a socket.
Definitions
def self.connected(endpoint, close_on_exec: false)
Create a connected endpoint from an existing endpoint.
Signature
-
parameter
endpointGeneric The endpoint to connect.
-
option
close_on_execBoolean Whether to close the socket on exec.
-
returns
ConnectedEndpoint A new connected endpoint instance.
Implementation
def self.connected(endpoint, close_on_exec: false)
socket = endpoint.connect
socket.close_on_exec = close_on_exec
return self.new(endpoint, socket, **endpoint.options)
end
def initialize(endpoint, socket, **options)
Initialize a new connected endpoint.
Signature
-
parameter
endpointGeneric The original endpoint that was connected.
-
parameter
socketSocket The socket that was connected.
-
parameter
optionsHash Additional options to pass to the parent class.
Implementation
def initialize(endpoint, socket, **options)
super(**options)
@endpoint = endpoint
@socket = socket
end
attr :endpoint
Signature
-
attribute
Generic The original endpoint that was connected.
attr :socket
Signature
-
attribute
Socket The socket that was connected.
def local_address_endpoint(**options)
A endpoint for the local end of the bound socket.
Signature
-
returns
AddressEndpoint A endpoint for the local end of the connected socket.
Implementation
def local_address_endpoint(**options)
AddressEndpoint.new(socket.to_io.local_address, **options)
end
def remote_address_endpoint(**options)
A endpoint for the remote end of the bound socket.
Signature
-
returns
AddressEndpoint A endpoint for the remote end of the connected socket.
Implementation
def remote_address_endpoint(**options)
AddressEndpoint.new(socket.to_io.remote_address, **options)
end
def connect(wrapper = self.wrapper, &block)
Connect using the already connected socket.
Signature
-
parameter
wrapperWrapper The wrapper to use (unused, socket is already connected).
-
yields
{|socket| ...} If a block is given, yields the connected socket.
-
parameter
socketSocket The connected socket.
-
parameter
-
returns
Socket The connected socket or a duplicate if no block is given.
Implementation
def connect(wrapper = self.wrapper, &block)
if block_given?
yield @socket
else
return @socket.dup
end
end
def close
Close the connected socket.
Implementation
def close
if @socket
@socket.close
@socket = nil
end
end
def to_s
Get a string representation of the connected endpoint.
Signature
-
returns
String A string representation of the connected endpoint.
Implementation
def to_s
"connected:#{@endpoint}"
end
def inspect
Get a detailed string representation of the connected endpoint.
Signature
-
returns
String A detailed string representation including the socket.
Implementation
def inspect
"\#<#{self.class} #{@socket} connected for #{@endpoint}>"
end