IO::EndpointSourceIOEndpointConnectedEndpoint

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 endpoint Generic

The endpoint to connect.

option close_on_exec Boolean

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 endpoint Generic

The original endpoint that was connected.

parameter socket Socket

The socket that was connected.

parameter options Hash

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 wrapper Wrapper

The wrapper to use (unused, socket is already connected).

yields {|socket| ...}

If a block is given, yields the connected socket.

parameter socket Socket

The connected socket.

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