Class: Async::IO::SocketEndpoint
- 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
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Attributes inherited from Endpoint
Instance Method Summary collapse
- #bind(&block) ⇒ Object
- #connect(&block) ⇒ Object
-
#initialize(socket, **options) ⇒ SocketEndpoint
constructor
A new instance of SocketEndpoint.
- #to_s ⇒ Object
Methods inherited from Endpoint
#accept, #bound, #each, each, #hostname, #linger, #local_address, parse, #reuse_address, #reuse_port, socket, ssl, tcp, #timeout, try_convert, udp, unix, #with
Constructor Details
permalink #initialize(socket, **options) ⇒ SocketEndpoint
Returns a new instance of SocketEndpoint.
29 30 31 32 33 34 |
# File 'lib/async/io/socket_endpoint.rb', line 29 def initialize(socket, **) super(**) # This socket should already be in the required state. @socket = Async::IO.try_convert(socket) end |
Instance Attribute Details
permalink #socket ⇒ Object (readonly)
Returns the value of attribute socket.
40 41 42 |
# File 'lib/async/io/socket_endpoint.rb', line 40 def socket @socket end |
Instance Method Details
permalink #bind(&block) ⇒ Object
[View source]
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/async/io/socket_endpoint.rb', line 42 def bind(&block) if block_given? begin yield @socket ensure @socket.reactor = nil end else return @socket end end |
permalink #connect(&block) ⇒ Object
[View source]
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/async/io/socket_endpoint.rb', line 54 def connect(&block) if block_given? begin yield @socket ensure @socket.reactor = nil end else return @socket end end |
permalink #to_s ⇒ Object
[View source]
36 37 38 |
# File 'lib/async/io/socket_endpoint.rb', line 36 def to_s "\#<#{self.class} #{@socket.inspect}>" end |