Class: Async::IO::SocketEndpoint

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/async/io/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, each, #each, #hostname, parse, ssl, tcp, try_convert, udp, unix

Constructor Details

#initialize(socket, **options) ⇒ SocketEndpoint

Returns a new instance of SocketEndpoint.



234
235
236
237
238
239
# File 'lib/async/io/endpoint.rb', line 234

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.



245
246
247
# File 'lib/async/io/endpoint.rb', line 245

def socket
  @socket
end

Instance Method Details

#bind(&block) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/async/io/endpoint.rb', line 247

def bind(&block)
  if block_given?
    yield @socket
  else
    return @socket
  end
end

#connect(&block) ⇒ Object



255
256
257
258
259
260
261
# File 'lib/async/io/endpoint.rb', line 255

def connect(&block)
  if block_given?
    yield @socket
  else
    return @socket
  end
end

#to_sObject



241
242
243
# File 'lib/async/io/endpoint.rb', line 241

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