From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 87D5D1F463 for ; Fri, 20 Dec 2019 01:39:33 +0000 (UTC) Received: from localhost ([::1]:49622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii7GO-0002jj-O2 for e@80x24.org; Thu, 19 Dec 2019 20:39:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35657) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii7GM-0002iV-H3 for dtas-all@nongnu.org; Thu, 19 Dec 2019 20:39:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii7GL-0001Nw-2j for dtas-all@nongnu.org; Thu, 19 Dec 2019 20:39:30 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:49602) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ii7GK-0001ER-QR for dtas-all@nongnu.org; Thu, 19 Dec 2019 20:39:28 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6AD6B1F464 for ; Fri, 20 Dec 2019 01:39:18 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH v2 1/5] pipe: avoid loading sleepy_penguin Date: Fri, 20 Dec 2019 01:39:13 +0000 Message-Id: <20191220013917.17212-2-e@80x24.org> In-Reply-To: <20191220013917.17212-1-e@80x24.org> References: <20191220013917.17212-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.71.152.64 X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" The values of F_{GET,SET}PIPE_SZ are architecture-independent and stable in Linux (unlike Ruby :P), so we won't need to bother loading an extra .so here for two constants. --- lib/dtas/pipe.rb | 20 ++++++++++++-------- test/test_sink_pipe_size.rb | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/dtas/pipe.rb b/lib/dtas/pipe.rb index 58d926c..4c3203d 100644 --- a/lib/dtas/pipe.rb +++ b/lib/dtas/pipe.rb @@ -1,10 +1,6 @@ # Copyright (C) 2013-2019 all contributors # License: GPL-3.0+ # frozen_string_literal: true -begin - require 'sleepy_penguin' -rescue LoadError -end require_relative '../dtas' require_relative 'writable_iter' require_relative 'nonblock' @@ -14,6 +10,11 @@ class DTAS::Pipe < DTAS::Nonblock # :nodoc: include DTAS::WritableIter attr_accessor :sink =20 + if RUBY_PLATFORM =3D~ /linux/i && File.readable?('/proc/sys/fs/pipe-ma= x-size') + F_SETPIPE_SZ =3D 1031 + F_GETPIPE_SZ =3D 1032 + end + def self.new _, w =3D rv =3D pipe w.writable_iter_init @@ -21,13 +22,16 @@ def self.new end =20 def pipe_size=3D(nr) - defined?(SleepyPenguin::F_SETPIPE_SZ) and - fcntl(SleepyPenguin::F_SETPIPE_SZ, nr) + fcntl(F_SETPIPE_SZ, nr) if defined?(F_SETPIPE_SZ) + rescue Errno::EINVAL # old kernel + rescue Errno::EPERM + # resizes fail if Linux is close to the pipe limit for the user + # or if the user does not have permissions to resize end =20 def pipe_size - fcntl(SleepyPenguin::F_GETPIPE_SZ) - end if defined?(SleepyPenguin::F_GETPIPE_SZ) + fcntl(F_GETPIPE_SZ) + end if defined?(F_GETPIPE_SZ) =20 # avoid syscall, we never change IO#nonblock=3D directly def nonblock? diff --git a/test/test_sink_pipe_size.rb b/test/test_sink_pipe_size.rb index 1b6db72..bbe2884 100644 --- a/test/test_sink_pipe_size.rb +++ b/test/test_sink_pipe_size.rb @@ -1,20 +1,17 @@ # Copyright (C) 2013-2019 all contributors # License: GPL-3.0+ # frozen_string_literal: true -begin - require 'sleepy_penguin' - require './test/player_integration' - class TestSinkPipeSizeIntegration < Testcase - include PlayerIntegration +require './test/player_integration' +class TestSinkPipeSizeIntegration < Testcase + include PlayerIntegration =20 - def test_sink_pipe_size_integration - s =3D client_socket - default_sink_pid(s) - s.req_ok("sink ed default pipe_size=3D0x1000") - s.req_ok("sink ed default pipe_size=3D0x10000") - s.req_ok("sink ed default pipe_size=3D") - s.req_ok("sink ed default pipe_size=3D4096") - end if SleepyPenguin.const_defined?(:F_SETPIPE_SZ) + def test_sink_pipe_size_integration + s =3D client_socket + default_sink_pid(s) + s.req_ok("sink ed default pipe_size=3D0x1000") + s.req_ok("sink ed default pipe_size=3D0x10000") + s.req_ok("sink ed default pipe_size=3D") + s.req_ok("sink ed default pipe_size=3D4096") end -rescue LoadError -end +end if RUBY_PLATFORM =3D~ /linux/i && + File.readable?('/proc/sys/fs/pipe-max-size')