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

Returns a new instance of AddressEndpoint.


29
30
31
32
33
# File 'lib/async/io/address_endpoint.rb', line 29

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address


39
40
41
# File 'lib/async/io/address_endpoint.rb', line 39

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

Returns:

  • (Socket)

    the bound socket


44
45
46
# File 'lib/async/io/address_endpoint.rb', line 44

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.

Returns:

  • (Socket)

    the connected socket


50
51
52
# File 'lib/async/io/address_endpoint.rb', line 50

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

#to_sObject


35
36
37
# File 'lib/async/io/address_endpoint.rb', line 35

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