From patchwork Fri May 21 08:32:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 29445 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 34AF827BC81; Fri, 21 May 2021 09:33:45 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id EB38927BC78 for ; Fri, 21 May 2021 09:33:44 +0100 (BST) Received: from localhost ([::1]:60430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lk0bI-00089o-4W for patchwork@mira.cbaines.net; Fri, 21 May 2021 04:33:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lk0ac-0007uz-Vj for guix-patches@gnu.org; Fri, 21 May 2021 04:33:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lk0ac-0008Li-Ju for guix-patches@gnu.org; Fri, 21 May 2021 04:33:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lk0ac-0006E2-He for guix-patches@gnu.org; Fri, 21 May 2021 04:33:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48556] [PATCH 3/4] progress: Add a download-size argument to progress-report-port. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 21 May 2021 08:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48556 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48556@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 48556-submit@debbugs.gnu.org id=B48556.162158595723875 (code B ref 48556); Fri, 21 May 2021 08:33:02 +0000 Received: (at 48556) by debbugs.gnu.org; 21 May 2021 08:32:37 +0000 Received: from localhost ([127.0.0.1]:35788 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lk0aD-0006Cz-EW for submit@debbugs.gnu.org; Fri, 21 May 2021 04:32:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33758) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lk0a8-0006CC-2K for 48556@debbugs.gnu.org; Fri, 21 May 2021 04:32:32 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36244) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lk0a2-0007zV-Sv for 48556@debbugs.gnu.org; Fri, 21 May 2021 04:32:26 -0400 Received: from [2a01:e0a:19b:d9a0:f2f7:a404:c3d3:f8b4] (port=37202 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lk0a2-0004xH-Bf; Fri, 21 May 2021 04:32:26 -0400 From: Mathieu Othacehe Date: Fri, 21 May 2021 10:32:18 +0200 Message-Id: <20210521083219.20714-3-othacehe@gnu.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210521083219.20714-1-othacehe@gnu.org> References: <20210521083219.20714-1-othacehe@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/progress.scm (progress-report-port): Add a download-size argument. --- guix/progress.scm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/guix/progress.scm b/guix/progress.scm index 334bd40547..0cbc804ec1 100644 --- a/guix/progress.scm +++ b/guix/progress.scm @@ -347,15 +347,25 @@ should be a object." (report total) (loop total (get-bytevector-n! in buffer 0 buffer-size)))))))) -(define* (progress-report-port reporter port #:key (close? #t)) +(define* (progress-report-port reporter port + #:key + (close? #t) + download-size) "Return a port that continuously reports the bytes read from PORT using REPORTER, which should be a object. When CLOSE? is true, -PORT is closed when the returned port is closed." +PORT is closed when the returned port is closed. + +When DOWNLOAD-SIZE is passed, do not read more than DOWNLOAD-SIZE bytes from +PORT. This is important to avoid blocking when the remote side won't close +the underlying connection." (match reporter (($ start report stop) (let* ((total 0) (read! (lambda (bv start count) - (let ((n (match (get-bytevector-n! port bv start count) + (let* ((count (if download-size + (min count (- download-size total)) + count)) + (n (match (get-bytevector-n! port bv start count) ((? eof-object?) 0) (x x)))) (set! total (+ total n))