Module: Kontena::Websocket::Client::Connection::Waitable_Ruby2_2

Included in:
Kontena::Websocket::Client::Connection
Defined in:
lib/kontena/websocket/client/connection.rb

Overview

ruby version <= 2.2

io/wait IO#wait_readable returns nil on EOF

Instance Method Summary collapse

Instance Method Details

#wait_socket_readable!(socket, timeout = nil) ⇒ Object

Parameters:

  • socket (Socket)
  • timeout (Float) (defaults to: nil)

    default (nil) blocks indefinitely

Raises:



37
38
39
40
41
42
43
# File 'lib/kontena/websocket/client/connection.rb', line 37

def wait_socket_readable!(socket, timeout = nil)
  debug "wait read: timeout=#{timeout}"

  unless IO.select([socket], nil, nil, timeout)
    raise Kontena::Websocket::TimeoutError, "read timeout after #{timeout}s"
  end
end

#wait_socket_writable!(socket, timeout = nil) ⇒ Object

Parameters:

  • socket (Socket)
  • timeout (Float) (defaults to: nil)

    default (nil) blocks indefinitely

Raises:



48
49
50
51
52
53
54
# File 'lib/kontena/websocket/client/connection.rb', line 48

def wait_socket_writable!(socket, timeout = nil)
  debug "wait write: timeout=#{timeout}"

  unless IO.select(nil, [socket], nil, timeout)
    raise Kontena::Websocket::TimeoutError, "write timeout after #{timeout}s"
  end
end