Class: DTAS::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/dtas/buffer.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ReadWrite, Splice

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



21
22
23
24
25
# File 'lib/dtas/buffer.rb', line 21

def initialize
  @bytes_xfer = 0
  @buffer_size = nil
  @to_io, @wr = DTAS::Pipe.new
end

Instance Attribute Details

#bytes_xferObject

Returns the value of attribute bytes_xfer.



19
20
21
# File 'lib/dtas/buffer.rb', line 19

def bytes_xfer
  @bytes_xfer
end

#to_ioObject (readonly)

call nread on this



17
18
19
# File 'lib/dtas/buffer.rb', line 17

def to_io
  @to_io
end

#wrObject (readonly)

processes (sources) should redirect to this



18
19
20
# File 'lib/dtas/buffer.rb', line 18

def wr
  @wr
end

Class Method Details

.load(hash) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/dtas/buffer.rb', line 27

def self.load(hash)
  buf = new
  if hash
    bs = hash["buffer_size"] and buf.buffer_size = bs
  end
  buf
end

Instance Method Details

#__dst_error(dst, e) ⇒ Object



39
40
41
42
# File 'lib/dtas/buffer.rb', line 39

def __dst_error(dst, e)
  warn "dropping #{dst.inspect} due to error: #{e.message} (#{e.class})"
  dst.close unless dst.closed?
end

#broadcast(targets) ⇒ Object

This will modify targets returns one of:

  • :wait_readable

  • subset of targets array for :wait_writable

  • some type of StandardError

  • nil



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dtas/buffer.rb', line 50

def broadcast(targets)
  bytes = inflight
  return :wait_readable if 0 == bytes # spurious wakeup

  case targets.size
  when 0
    :ignore # this will pause decoders
  when 1
    broadcast_one(targets, bytes)
  else # infinity
    broadcast_inf(targets, bytes)
  end
end

#buf_resetObject



79
80
81
82
83
84
# File 'lib/dtas/buffer.rb', line 79

def buf_reset
  close!
  @bytes_xfer = 0
  @to_io, @wr = DTAS::Pipe.new
  @wr.pipe_size = @buffer_size if @buffer_size
end

#closeObject

don’t really close the pipes under normal circumstances, just clear data



74
75
76
77
# File 'lib/dtas/buffer.rb', line 74

def close
  bytes = inflight
  discard(bytes) if bytes > 0
end

#close!Object



86
87
88
89
# File 'lib/dtas/buffer.rb', line 86

def close!
  @to_io.close
  @wr.close
end

#inflightObject



69
70
71
# File 'lib/dtas/buffer.rb', line 69

def inflight
  @to_io.nread
end

#readable_iter {|_self, nil| ... } ⇒ Object

Yields:

  • (_self, nil)

Yield Parameters:

  • _self (DTAS::Buffer)

    the object that the method was called on



64
65
66
67
# File 'lib/dtas/buffer.rb', line 64

def readable_iter
  # this calls DTAS::Buffer#broadcast from DTAS::Player
  yield(self, nil)
end

#to_hshObject



35
36
37
# File 'lib/dtas/buffer.rb', line 35

def to_hsh
  @buffer_size ? { "buffer_size" => @buffer_size } : {}
end