From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 49380202C1; Fri, 10 Mar 2017 00:44:07 +0000 (UTC) Date: Fri, 10 Mar 2017 00:44:07 +0000 From: Eric Wong To: http_spew-public@bogomips.org Subject: [PATCH 2/1] make kgio entirely optional Message-ID: <20170310004407.GA22169@starla> References: <20170309204324.1718-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20170309204324.1718-1-e@80x24.org> List-Id: We may emulate Kgio.poll inefficiently using IO.select; and perhaps IO.select in Ruby can be modified to transparently use ppoll() on Linux... --- http_spew.gemspec | 1 - lib/http_spew/class_methods.rb | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/http_spew.gemspec b/http_spew.gemspec index d4d38da..a5e4908 100644 --- a/http_spew.gemspec +++ b/http_spew.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |s| s.summary = summary s.test_files = Dir["test/test_*.rb"] s.add_dependency(%q, [ "~> 0.3", ">= 0.3.1"]) - s.add_dependency(%q, "~> 2.6") s.add_development_dependency(%q, "~> 1.0") s.required_ruby_version = '>= 2.3' s.licenses = %w(GPL-2.0+) diff --git a/lib/http_spew/class_methods.rb b/lib/http_spew/class_methods.rb index 79b3e47..dda0e19 100644 --- a/lib/http_spew/class_methods.rb +++ b/lib/http_spew/class_methods.rb @@ -110,7 +110,7 @@ module HTTP_Spew::ClassMethods break if pollset.empty? busy = pollset.keys - rv = with_timeout(t) { Kgio.poll(pollset, (t[0] * 1000).to_i) } or break + rv = with_timeout(t) { do_poll(pollset, t[0]) } or break end while t[0] > 0.0 && requests = rv.keys.concat(busy).uniq! ready.concat(failed) @@ -121,4 +121,32 @@ module HTTP_Spew::ClassMethods end ready end + + begin + require 'kgio' + def do_poll(pollset, sec) # :nodoc: + Kgio.poll(pollset, (sec * 1000).to_i) + end + rescue LoadError + # emulate Kgio.poll with IO.select + def do_poll(pollset, sec) # :nodoc: + rd = [] + wr = [] + pollset.each do |io, events| + case events + when :wait_readable + rd << io + when :wait_writable + wr << io + else + raise "BUG: unsupported event #{event.inspect} for #{io.inspect}" + end + end + ready = IO.select(rd, wr, nil, sec) or return + pollset.clear + ready[0].each { |io| pollset[io] = 1 } # POLLIN + ready[1].each { |io| pollset[io] = 4 } # POLLOUT + pollset + end + end end -- EW