CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/channel/stream_abstraction.rb
Views: 1904
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