class Proxy::RemoteExecution::Cockpit::OpenSSLBufferedSocket

Public Class Methods

applies_for?(socket) click to toggle source
# File lib/smart_proxy_remote_execution_ssh/cockpit.rb, line 49
def self.applies_for?(socket)
  socket.is_a? ::OpenSSL::SSL::SSLSocket
end

Public Instance Methods

recv(n) click to toggle source
# File lib/smart_proxy_remote_execution_ssh/cockpit.rb, line 54
def recv(n)
  res = ""
  begin
    # To drain a SSLSocket before we can go back to the event
    # loop, we need to repeatedly call read_nonblock; a single
    # call is not enough.
    while true
      res += @socket.read_nonblock(n)
    end
  rescue IO::WaitReadable
    # Sometimes there is no payload after reading everything
    # from the underlying socket, but a empty string is treated
    # as EOF by Net::SSH. So we block a bit until we have
    # something to return.
    if res == ""
      IO.select([@socket.to_io])
      retry
    else
      res
    end
  rescue IO::WaitWritable
    # A renegotiation is happening, let it proceed.
    IO.select(nil, [@socket.to_io])
    retry
  end
end
send(mesg, flags) click to toggle source
# File lib/smart_proxy_remote_execution_ssh/cockpit.rb, line 81
def send(mesg, flags)
  begin
    @socket.write_nonblock(mesg)
  rescue IO::WaitWritable
    0
  rescue IO::WaitReadable
    IO.select([@socket.to_io])
    retry
  end
end