IO::EndpointSourceIOEndpointAddressEndpoint

class AddressEndpoint

Represents an endpoint for a specific network address.

Definitions

def initialize(address, **options)

Initialize a new address endpoint.

Signature

parameter address Address

The network address for this endpoint.

parameter options Hash

Additional options to pass to the parent class.

Implementation

def initialize(address, **options)
	super(**options)
	
	@address = address
end

def to_s

Get a string representation of the endpoint.

Signature

returns String

A string representation of the endpoint address.

Implementation

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

def inspect

Get a detailed string representation of the endpoint.

Signature

returns String

A detailed string representation including the address.

Implementation

def inspect
	"\#<#{self.class} address=#{@address.inspect}>"
end

attr :address

Signature

attribute Address

The network address for this endpoint.

def bind(wrapper = self.wrapper, &block)

Bind a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.

Signature

yields {|socket| ...}

If a block is given, yields the bound socket.

parameter socket Socket

The socket which has been bound.

returns Array(Socket)

the bound socket

Implementation

def bind(wrapper = self.wrapper, &block)
	[wrapper.bind(@address, **@options, &block)]
end

def connect(wrapper = self.wrapper, &block)

Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.

Signature

returns Socket

the connected socket

Implementation

def connect(wrapper = self.wrapper, &block)
	wrapper.connect(@address, **@options, &block)
end