Class: IO::Endpoint::ConnectedEndpoint

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

Instance Attribute Summary collapse

Attributes inherited from Generic

#options

Class Method Summary collapse

Instance Method Summary collapse

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

Returns a new instance of ConnectedEndpoint.



22
23
24
25
26
27
# File 'lib/io/endpoint/connected_endpoint.rb', line 22

def initialize(endpoint, socket, **options)
	super(**options)
	
	@endpoint = endpoint
	@socket = socket
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



29
30
31
# File 'lib/io/endpoint/connected_endpoint.rb', line 29

def endpoint
  @endpoint
end

#socketObject (readonly)

Returns the value of attribute socket.



30
31
32
# File 'lib/io/endpoint/connected_endpoint.rb', line 30

def socket
  @socket
end

Class Method Details

.connected(endpoint, close_on_exec: false) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/io/endpoint/connected_endpoint.rb', line 14

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

Instance Method Details

#closeObject



52
53
54
55
56
57
# File 'lib/io/endpoint/connected_endpoint.rb', line 52

def close
	if @socket
		@socket.close
		@socket = nil
	end
end

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



44
45
46
47
48
49
50
# File 'lib/io/endpoint/connected_endpoint.rb', line 44

def connect(wrapper = self.wrapper, &block)
	if block_given?
		yield @socket
	else
		return @socket.dup
	end
end

#inspectObject



63
64
65
# File 'lib/io/endpoint/connected_endpoint.rb', line 63

def inspect
	"\#<#{self.class} #{@socket} connected for #{@endpoint}>"
end

#local_address_endpoint(**options) ⇒ Object

A endpoint for the local end of the bound socket.



34
35
36
# File 'lib/io/endpoint/connected_endpoint.rb', line 34

def local_address_endpoint(**options)
	AddressEndpoint.new(socket.to_io.local_address, **options)
end

#remote_address_endpoint(**options) ⇒ Object

A endpoint for the remote end of the bound socket.



40
41
42
# File 'lib/io/endpoint/connected_endpoint.rb', line 40

def remote_address_endpoint(**options)
	AddressEndpoint.new(socket.to_io.remote_address, **options)
end

#to_sObject



59
60
61
# File 'lib/io/endpoint/connected_endpoint.rb', line 59

def to_s
	"connected:#{@endpoint}"
end