Class: IO::Endpoint::AddressEndpoint

Inherits:
Generic
  • Object
show all
Defined in:
lib/io/endpoint/address_endpoint.rb

Overview

Represents an endpoint for a specific network address.

Direct Known Subclasses

UNIXEndpoint

Instance Attribute Summary collapse

Attributes inherited from Generic

#options

Instance Method Summary collapse

Methods inherited from Generic

#accept, #bound, #connected, #each, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #with, #wrapper

Constructor Details

#initialize(address, **options) ⇒ AddressEndpoint

Initialize a new address endpoint.



17
18
19
20
21
# File 'lib/io/endpoint/address_endpoint.rb', line 17

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



43
44
45
# File 'lib/io/endpoint/address_endpoint.rb', line 43

def address
  @address
end

#The network address for this endpoint.(networkaddress) ⇒ Object (readonly)



43
# File 'lib/io/endpoint/address_endpoint.rb', line 43

attr :address

Instance Method Details

#bind(wrapper = self.wrapper, &block) ⇒ Object

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



49
50
51
# File 'lib/io/endpoint/address_endpoint.rb', line 49

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

#connect(wrapper = self.wrapper, &block) ⇒ Object

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



55
56
57
# File 'lib/io/endpoint/address_endpoint.rb', line 55

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

#inspectObject

Get a detailed string representation of the endpoint.



38
39
40
# File 'lib/io/endpoint/address_endpoint.rb', line 38

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

#to_sObject

Get a string representation of the endpoint.



25
26
27
28
29
30
31
32
33
34
# File 'lib/io/endpoint/address_endpoint.rb', line 25

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