From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-2.3 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id BAD101F848 for ; Wed, 18 Feb 2015 22:53:45 +0000 (UTC) Received: from localhost ([::1]:53969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YODV3-0000fU-8H for dtas-all@80x24.org; Wed, 18 Feb 2015 17:53:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOD2F-0006dR-RW for dtas-all@nongnu.org; Wed, 18 Feb 2015 17:24:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOD28-0001FH-UJ for dtas-all@nongnu.org; Wed, 18 Feb 2015 17:23:59 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:53166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOD28-0001FB-Ot for dtas-all@nongnu.org; Wed, 18 Feb 2015 17:23:52 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 785181F807 for ; Wed, 18 Feb 2015 22:23:49 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH 2/2] buffer: allow limiting the amount of bytes output Date: Wed, 18 Feb 2015 22:23:49 +0000 Message-Id: <1424298229-17600-2-git-send-email-e@80x24.org> In-Reply-To: <1424298229-17600-1-git-send-email-e@80x24.org> References: <1424298229-17600-1-git-send-email-e@80x24.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org This will aid in allowing us to create effects which affect only a certain part of a track. --- lib/dtas/buffer.rb | 6 +++--- lib/dtas/buffer/read_write.rb | 9 +++++---- lib/dtas/buffer/splice.rb | 9 +++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/dtas/buffer.rb b/lib/dtas/buffer.rb index b03ed8a..23b0b77 100644 --- a/lib/dtas/buffer.rb +++ b/lib/dtas/buffer.rb @@ -48,14 +48,14 @@ def __dst_error(dst, e) # - subset of targets array for :wait_writable # - some type of StandardError # - nil - def broadcast(targets) + def broadcast(targets, limit = nil) case targets.size when 0 :ignore # this will pause decoders when 1 - broadcast_one(targets) + broadcast_one(targets, limit) else # infinity - broadcast_inf(targets) + broadcast_inf(targets, limit) end end 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 @@ def discard(bytes) 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 @@ def broadcast_one(targets) 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 @@ def broadcast_inf(targets) # 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 diff --git a/lib/dtas/buffer/splice.rb b/lib/dtas/buffer/splice.rb index b987f3a..02ce877 100644 --- a/lib/dtas/buffer/splice.rb +++ b/lib/dtas/buffer/splice.rb @@ -28,9 +28,10 @@ def discard(bytes) IO.splice(@to_io, nil, DEVNULL, nil, bytes) end - def broadcast_one(targets) + def broadcast_one(targets, limit = nil) # single output is always non-blocking - s = IO.trysplice(@to_io, nil, targets[0], nil, MAX_AT_ONCE_1, F_MOVE) + limit ||= MAX_AT_ONCE_1 + s = IO.trysplice(@to_io, nil, targets[0], nil, limit, F_MOVE) if Symbol === s targets # our one and only target blocked on write else @@ -88,7 +89,7 @@ def __broadcast_tee(blocked, targets, chunk_size) most_teed end - def broadcast_inf(targets) + def broadcast_inf(targets, limit = nil) if targets.all?(&:ready_write_optimized?) blocked = [] elsif targets.none?(&:nonblock?) @@ -105,7 +106,7 @@ def broadcast_inf(targets) end # don't pin too much on one target - bytes = MAX_AT_ONCE + bytes = limit || MAX_AT_ONCE last = targets.pop # we splice to the last one, tee to the rest # this may return zero if all targets were non-blocking -- EW