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


243
244
245
246
247
# File 'lib/rex/io/ring_buffer.rb', line 243

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

Instance Attribute Details

#buffObject

Returns the value of attribute buff


241
242
243
# File 'lib/rex/io/ring_buffer.rb', line 241

def buff
  @buff
end

#ringObject

Returns the value of attribute ring


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

def ring
  @ring
end

#seqObject

Returns the value of attribute seq


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

def seq
  @seq
end

Instance Method Details

#read(len = nil) ⇒ Object


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
275
276
277
278
279
# File 'lib/rex/io/ring_buffer.rb', line 249

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


281
282
283
# File 'lib/rex/io/ring_buffer.rb', line 281

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