Class: Async::IO::SocketEndpoint

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/async/io/socket_endpoint.rb

Overview

This class doesn’t exert ownership over the specified socket, wraps a native ::IO.

Instance Attribute Summary collapse

Attributes inherited from Endpoint

#options

Instance Method Summary collapse

Methods inherited from Endpoint

#accept, #bound, composite, #connected, each, #each, #hostname, #linger, #local_address, parse, #reuse_address, #reuse_port, socket, ssl, tcp, #timeout, try_convert, udp, unix, #with

Constructor Details

#initialize(socket, **options) ⇒ SocketEndpoint

Returns a new instance of SocketEndpoint.



12
13
14
15
16
17
# File 'lib/async/io/socket_endpoint.rb', line 12

def initialize(socket, **options)
	super(**options)
	
	# This socket should already be in the required state.
	@socket = Async::IO.try_convert(socket)
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



23
24
25
# File 'lib/async/io/socket_endpoint.rb', line 23

def socket
  @socket
end

Instance Method Details

#bind(&block) ⇒ Object



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

def bind(&block)
	if block_given?
		begin
			yield @socket
		ensure
			@socket.reactor = nil
		end
	else
		return @socket
	end
end

#connect(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/async/io/socket_endpoint.rb', line 37

def connect(&block)
	if block_given?
		begin
			yield @socket
		ensure
			@socket.reactor = nil
		end
	else
		return @socket
	end
end

#to_sObject



19
20
21
# File 'lib/async/io/socket_endpoint.rb', line 19

def to_s
	"\#<#{self.class} #{@socket.inspect}>"
end