class Rex::IO::RingBuffer::Stream
This class provides a backwards compatible “stream” socket that uses the parents ring buffer.
Attributes
buff[RW]
ring[RW]
seq[RW]
Public Class Methods
new(ring)
click to toggle source
# File lib/rex/io/ring_buffer.rb, line 242 def initialize(ring) self.ring = ring self.seq = ring.base_sequence self.buff = '' end
Public Instance Methods
read(len=nil)
click to toggle source
# File lib/rex/io/ring_buffer.rb, line 248 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)
click to toggle source
# File lib/rex/io/ring_buffer.rb, line 280 def write(data) self.ring.write(data) end