module Proxy::RemoteExecution::NetSSHCompat::BufferedIO
Public Instance Methods
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
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
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
# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 176 def pending_writes? output.length.positive? end
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
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
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
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
# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 211 def input @input end
# File lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb, line 215 def output @output end