Class: IO::Endpoint::SocketEndpoint

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

Overview

This class doesn’t exert ownership over the specified socket, wraps a native ::IO.

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(socket, **options) ⇒ SocketEndpoint

Initialize a new socket endpoint.



14
15
16
17
18
# File 'lib/io/endpoint/socket_endpoint.rb', line 14

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

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



33
34
35
# File 'lib/io/endpoint/socket_endpoint.rb', line 33

def socket
  @socket
end

Instance Method Details

#bind(&block) ⇒ Object

Bind using the wrapped socket.



39
40
41
42
43
44
45
# File 'lib/io/endpoint/socket_endpoint.rb', line 39

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

#connect(&block) ⇒ Object

Connect using the wrapped socket.



51
52
53
54
55
56
57
# File 'lib/io/endpoint/socket_endpoint.rb', line 51

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

#inspectObject

Get a detailed string representation of the socket endpoint.



28
29
30
# File 'lib/io/endpoint/socket_endpoint.rb', line 28

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

#The wrapped socket.=(wrappedsocket. = (value)) ⇒ Object



33
# File 'lib/io/endpoint/socket_endpoint.rb', line 33

attr :socket

#to_sObject

Get a string representation of the socket endpoint.



22
23
24
# File 'lib/io/endpoint/socket_endpoint.rb', line 22

def to_s
  "socket:#{@socket}"
end