module Proxy::RemoteExecution::NetSSHCompat::BufferedIO

Public Instance Methods

available() click to toggle source

Returns the number of bytes available to be read from the input buffer. (See read_available.)

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 166
def available
  input.available
end
enqueue(data) click to toggle source

Enqueues data in the output buffer, to be written when send_pending is called. Note that the data is not sent immediately by this method!

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 172
def enqueue(data)
  output.append(data)
end
fill(count = 8192) click to toggle source

Tries to read up to n bytes of data from the remote end, and appends the data to the input buffer. It returns the number of bytes read, or 0 if no data was available to be read.

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 148
def fill(count = 8192)
  input.consume!
  data = recv(count)
  input.append(data)
  return data.length
rescue EOFError => e
  @input_errors << e
  return 0
end
pending_writes?() click to toggle source
# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 176
def pending_writes?
  output.length.positive?
end
read_available(length = nil) click to toggle source

Read up to length bytes from the input buffer. If length is nil, all available data is read from the buffer. (See available.)

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 160
def read_available(length = nil)
  input.read(length || available)
end
send_pending() click to toggle source

Sends as much of the pending output as possible. Returns true if any data was sent, and false otherwise.

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 182
def send_pending
  if pending_writes?
    sent = send(output.to_s, 0)
    output.consume!(sent)
    return sent.positive?
  else
    return false
  end
end
wait_for_pending_sends() click to toggle source

Calls send_pending repeatedly, if necessary, blocking until the output buffer is empty.

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 194
def wait_for_pending_sends
  send_pending
  while pending_writes?
    result = IO.select(nil, [self]) || next
    next unless result[1].any?

    send_pending
  end
end

Private Instance Methods

initialize_buffered_io() click to toggle source

Initializes the intput and output buffers for this object. This method is called automatically when the module is mixed into an object via Object#extend (see Net::SSH::BufferedIo.extended), but must be called explicitly in the initialize method of any class that uses Module#include to add this module.

# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 224
def initialize_buffered_io
  @input = Buffer.new
  @input_errors = []
  @output = Buffer.new
  @output_errors = []
end
input() click to toggle source
# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 211
def input
  @input
end
output() click to toggle source
# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 215
def output
  @output
end