From: Eric Wong <e@80x24.org>
To: http_spew-public@bogomips.org
Subject: [PATCH 2/1] make kgio entirely optional
Date: Fri, 10 Mar 2017 00:44:07 +0000 [thread overview]
Message-ID: <20170310004407.GA22169@starla> (raw)
In-Reply-To: <20170309204324.1718-1-e@80x24.org>
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<kcar>, [ "~> 0.3", ">= 0.3.1"])
- s.add_dependency(%q<kgio>, "~> 2.6")
s.add_development_dependency(%q<olddoc>, "~> 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
prev parent reply other threads:[~2017-03-10 0:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 20:43 [PATCH] remove most uses of kgio Eric Wong
2017-03-10 0:44 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/http_spew/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170310004407.GA22169@starla \
--to=e@80x24.org \
--cc=http_spew-public@bogomips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/http_spew.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox