Class: Proxy::RemoteExecution::Cockpit::OpenSSLBufferedSocket

Inherits:
BufferedSocket
  • Object
show all
Defined in:
lib/smart_proxy_remote_execution_ssh/cockpit.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BufferedSocket

build, #initialize

Constructor Details

This class inherits a constructor from Proxy::RemoteExecution::Cockpit::BufferedSocket

Class Method Details

.applies_for?(socket) ⇒ Boolean



50
51
52
# File 'lib/smart_proxy_remote_execution_ssh/cockpit.rb', line 50

def self.applies_for?(socket)
  socket.is_a? ::OpenSSL::SSL::SSLSocket
end

Instance Method Details

#recv(n) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/smart_proxy_remote_execution_ssh/cockpit.rb', line 55

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.
    loop do
      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) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/smart_proxy_remote_execution_ssh/cockpit.rb', line 82

def send(mesg, flags)
  @socket.write_nonblock(mesg)
rescue IO::WaitWritable
  0
rescue IO::WaitReadable
  IO.select([@socket.to_io])
  retry
end