CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/channel/stream_abstraction.rb
Views: 11783
1
# -*- coding: binary -*-
2
3
require 'rex/io/stream_abstraction'
4
5
module Rex
6
module Post
7
module Channel
8
module StreamAbstraction
9
include Rex::IO::StreamAbstraction
10
11
#
12
# Read *length* bytes from the channel. If the operation times out, the data
13
# that was read will be returned or nil if no data was read.
14
#
15
def read(length = nil)
16
if closed?
17
raise IOError, 'Channel has been closed.', caller
18
end
19
20
buf = ''
21
length = 65536 if length.nil?
22
23
begin
24
buf << lsock.recv(length - buf.length) while buf.length < length
25
rescue StandardError
26
buf = nil if buf.empty?
27
end
28
29
buf
30
end
31
end
32
end
33
end
34
end
35
36