Class: Rex::IO::RingBuffer::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/io/ring_buffer.rb

Overview

This class provides a backwards compatible “stream” socket that uses the parents ring buffer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ring) ⇒ Stream

Returns a new instance of Stream.



238
239
240
241
242
# File 'lib/rex/io/ring_buffer.rb', line 238

def initialize(ring)
	self.ring = ring
	self.seq  = ring.base_sequence
	self.buff = ''
end

Instance Attribute Details

#buffObject

Returns the value of attribute buff.



236
237
238
# File 'lib/rex/io/ring_buffer.rb', line 236

def buff
  @buff
end

#ringObject

Returns the value of attribute ring.



234
235
236
# File 'lib/rex/io/ring_buffer.rb', line 234

def ring
  @ring
end

#seqObject

Returns the value of attribute seq.



235
236
237
# File 'lib/rex/io/ring_buffer.rb', line 235

def seq
  @seq
end

Instance Method Details

#read(len = nil) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/rex/io/ring_buffer.rb', line 244

def read(len=nil)
	if len and self.buff.length >= len
		data = self.buff.slice!(0,len)
		return data
	end

	while true
		lseq, data = self.ring.read_data( self.seq )
		return if not lseq
	
		self.seq  = lseq
		self.buff << data
		if len
			if self.buff.length >= len
				return self.buff.slice!(0,len)
			else
				IO.select(nil, nil, nil, 0.25)
				next
			end
		end
		
		data = self.buff
		self.buff = ''
		
		return data
		
		# Not reached
		break
	end
			
end

#write(data) ⇒ Object



276
277
278
# File 'lib/rex/io/ring_buffer.rb', line 276

def write(data)
	self.ring.write(data)
end