Module: Proxy::RemoteExecution::NetSSHCompat::BufferedIO

Included in:
Cockpit::BufferedSocket
Defined in:
lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb

Instance Method Summary collapse

Instance Method Details

#availableObject

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



166
167
168
# File 'lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb', line 166

def available
  input.available
end

#enqueue(data) ⇒ Object

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!



172
173
174
# File 'lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb', line 172

def enqueue(data)
  output.append(data)
end

#fill(count = 8192) ⇒ Object

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.



148
149
150
151
152
153
154
155
156
# 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?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb', line 176

def pending_writes?
  output.length.positive?
end

#read_available(length = nil) ⇒ Object

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



160
161
162
# File 'lib/smart_proxy_remote_execution_ssh/net_ssh_compat.rb', line 160

def read_available(length = nil)
  input.read(length || available)
end

#send_pendingObject

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



182
183
184
185
186
187
188
189
190
# 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_sendsObject

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



194
195
196
197
198
199
200
201
202
# 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