Module: Rex::Post::Channel::StreamAbstraction

Includes:
IO::StreamAbstraction
Included in:
Msf::Sessions::SshCommandShellBind::TcpClientChannel, Rex::Proto::Http::WebSocket::Interface::Channel
Defined in:
lib/rex/post/channel/stream_abstraction.rb

Instance Method Summary collapse

Instance Method Details

#read(length = nil) ⇒ Object

Read length bytes from the channel. If the operation times out, the data that was read will be returned or nil if no data was read.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rex/post/channel/stream_abstraction.rb', line 15

def read(length = nil)
  if closed?
    raise IOError, 'Channel has been closed.', caller
  end

  buf = ''
  length = 65536 if length.nil?

  begin
    buf << lsock.recv(length - buf.length) while buf.length < length
  rescue StandardError
    buf = nil if buf.empty?
  end

  buf
end