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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

#accept, each, #each, #hostname, parse, #reuse_port, socket, ssl, tcp, #timeout, try_convert, udp, unix

Constructor Details

#initialize(address, **options) ⇒ AddressEndpoint

Returns a new instance of AddressEndpoint.



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

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



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

def address
  @address
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
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



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

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