Class: Async::IO::AddressEndpoint

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

Overview

This class will open and close the socket automatically.

Direct Known Subclasses

UNIXEndpoint

Instance Attribute Summary collapse

Attributes inherited from Endpoint

#options

Instance Method Summary collapse

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

#initialize(address, **options) ⇒ AddressEndpoint



27
28
29
30
31
# File 'lib/async/io/address_endpoint.rb', line 27

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



37
38
39
# File 'lib/async/io/address_endpoint.rb', line 37

def address
  @address
end

Instance Method Details

#bind {|Socket| ... } ⇒ Socket

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

Yields:

  • (Socket)

    the bound socket



42
43
44
# File 'lib/async/io/address_endpoint.rb', line 42

def bind(&block)
  Socket.bind(@address, **@options, &block)
end

#connect(&block) ⇒ Socket

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



48
49
50
# File 'lib/async/io/address_endpoint.rb', line 48

def connect(&block)
  Socket.connect(@address, **@options, &block)
end

#to_sObject



33
34
35
# File 'lib/async/io/address_endpoint.rb', line 33

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