Class: IO::Endpoint::AddressEndpoint

Inherits:
Generic
  • Object
show all
Defined in:
lib/io/endpoint/address_endpoint.rb

Direct Known Subclasses

UNIXEndpoint

Instance Attribute Summary collapse

Attributes inherited from Generic

#options

Instance Method Summary collapse

Methods inherited from Generic

#accept, #bound, #connected, #each, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #with, #wrapper

Constructor Details

#initialize(address, **options) ⇒ AddressEndpoint

Returns a new instance of AddressEndpoint.



13
14
15
16
17
# File 'lib/io/endpoint/address_endpoint.rb', line 13

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



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

def address
  @address
end

Instance Method Details

#bind(wrapper = self.wrapper) {||socket| ...| ... } ⇒ Array(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| ...)

    An optional block which will be passed the socket. @parameter socket [Socket] The socket which has been bound.

Returns:

  • (Array(Socket))

    the bound socket



40
41
42
# File 'lib/io/endpoint/address_endpoint.rb', line 40

def bind(wrapper = self.wrapper, &block)
  [wrapper.bind(@address, **@options, &block)]
end

#connect(wrapper = self.wrapper, &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



46
47
48
# File 'lib/io/endpoint/address_endpoint.rb', line 46

def connect(wrapper = self.wrapper, &block)
  wrapper.connect(@address, **@options, &block)
end

#inspectObject



30
31
32
# File 'lib/io/endpoint/address_endpoint.rb', line 30

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

#to_sObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/io/endpoint/address_endpoint.rb', line 19

def to_s
  case @address.afamily
  when Socket::AF_INET
    "inet:#{@address.inspect_sockaddr}"
  when Socket::AF_INET6
    "inet6:#{@address.inspect_sockaddr}"
  else
    "address:#{@address.inspect_sockaddr}"
  end
end