Class: ESM::Connection::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/esm/connection/socket.rb

Direct Known Subclasses

ClientSocket, ServerSocket

Constant Summary collapse

IGNORED_IO_ERRORS =
[
  "closed stream",
  "stream closed in another thread",
  "uninitialized stream"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Socket

Returns a new instance of Socket.



16
17
18
19
# File 'lib/esm/connection/socket.rb', line 16

def initialize(socket)
  @socket = socket
  @address = socket.local_address.inspect_sockaddr
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



12
13
14
# File 'lib/esm/connection/socket.rb', line 12

def address
  @address
end

Instance Method Details

#closeObject



29
30
31
32
33
34
35
# File 'lib/esm/connection/socket.rb', line 29

def close(...)
  @socket.close(...)
rescue Errno::ENOTCONN
rescue IOError => e
  return if ignored_io_error?(e)
  raise
end

#readable?(timeout = 3) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/esm/connection/socket.rb', line 37

def readable?(timeout = 3)
  wait_readable(timeout).first.size > 0
end

#shutdownObject



21
22
23
24
25
26
27
# File 'lib/esm/connection/socket.rb', line 21

def shutdown(...)
  @socket.shutdown(...)
rescue Errno::ENOTCONN
rescue IOError => e
  return if ignored_io_error?(e)
  raise
end

#writeable?(timeout = 3) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/esm/connection/socket.rb', line 41

def writeable?(timeout = 3)
  wait_writeable(timeout).second.size > 0
end