about summary refs log tree commit homepage
path: root/lib/dtas/buffer/read_write.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-02-04 07:09:29 +0000
committerEric Wong <e@80x24.org>2015-02-04 07:09:29 +0000
commit33746aa40a70e38aa8386d81d1f22a884db3ed9f (patch)
tree7646a5d2fa70f5f76792aa90c2e05690feff23f3 /lib/dtas/buffer/read_write.rb
parent2946d628a4853c7c130778ea62ffa2c6bbcadcc3 (diff)
downloaddtas-tfx-pu.tar.gz
This will aid in allowing us to create effects which affect
only a certain part of a track.
Diffstat (limited to 'lib/dtas/buffer/read_write.rb')
-rw-r--r--lib/dtas/buffer/read_write.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/dtas/buffer/read_write.rb b/lib/dtas/buffer/read_write.rb
index a27b823..64ad297 100644
--- a/lib/dtas/buffer/read_write.rb
+++ b/lib/dtas/buffer/read_write.rb
@@ -26,9 +26,9 @@ module DTAS::Buffer::ReadWrite # :nodoc:
   end
 
   # always block when we have a single target
-  def broadcast_one(targets)
+  def broadcast_one(targets, limit = nil)
     buf = _rbuf
-    @to_io.read_nonblock(MAX_AT_ONCE, buf)
+    @to_io.read_nonblock(limit || MAX_AT_ONCE, buf)
     n = targets[0].write(buf) # IO#write has write-in-full behavior
     @bytes_xfer += n
     :wait_readable
@@ -42,7 +42,7 @@ module DTAS::Buffer::ReadWrite # :nodoc:
     nil # do not return error here, we already spewed an error message
   end
 
-  def broadcast_inf(targets)
+  def broadcast_inf(targets, limit = nil)
     nr_nb = targets.count(&:nonblock?)
     if nr_nb == 0 || nr_nb == targets.size
       # if all targets are full, don't start until they're all writable
@@ -61,7 +61,8 @@ module DTAS::Buffer::ReadWrite # :nodoc:
 
     # don't pin too much on one target
     bytes = inflight
-    bytes = bytes > MAX_AT_ONCE ? MAX_AT_ONCE : bytes
+    limit ||= MAX_AT_ONCE
+    bytes = bytes > limit ? limit : bytes
     buf = _rbuf
     @to_io.read(bytes, buf)
     n = buf.bytesize