sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] kqueue: remove IO#autoclose= and 1.8-related checks
@ 2017-03-22  1:41 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-03-22  1:41 UTC (permalink / raw)
  To: sleepy-penguin

We only support modern Rubies, so IO#autoclose= is implicit
and we should not be wasting bytecode checking for it.
---
 ext/sleepy_penguin/kqueue.c  | 7 +++----
 lib/sleepy_penguin/kqueue.rb | 8 ++------
 test/test_kqueue.rb          | 3 +--
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/ext/sleepy_penguin/kqueue.c b/ext/sleepy_penguin/kqueue.c
index 114e78a..430bc88 100644
--- a/ext/sleepy_penguin/kqueue.c
+++ b/ext/sleepy_penguin/kqueue.c
@@ -101,11 +101,10 @@ static struct kq_per_thread *kpt_get(int nchanges, int nevents)
  * Creates a new Kqueue::IO object.  This is a wrapper around the kqueue(2)
  * system call which creates a Ruby IO object around the kqueue descriptor.
  *
- * kqueue descriptors are automatically invalidated across fork, so care
- * must be taken when forking.
+ * kqueue descriptors are automatically invalidated by the OS across fork,
+ * so care must be taken when forking.
  * Setting IO#autoclose=false is recommended for applications which fork
- * after kqueue creation.  Ruby 1.8 does not have IO#autoclose=, so using
- * this class is not recommended under Ruby 1.8
+ * after kqueue creation.
  */
 static VALUE s_new(VALUE klass)
 {
diff --git a/lib/sleepy_penguin/kqueue.rb b/lib/sleepy_penguin/kqueue.rb
index d460669..2620a12 100644
--- a/lib/sleepy_penguin/kqueue.rb
+++ b/lib/sleepy_penguin/kqueue.rb
@@ -1,8 +1,8 @@
 require 'thread'
 require_relative 'kevent'
 
-# The high-level Kqueue interface.  This provides fork-safety under Ruby 1.9
-# and later (but not Ruby 1.8).
+# The high-level Kqueue interface.  This provides fork-safety; as
+# underlying kqueue descriptors are closed by the OS upon fork.
 # This also provides memory protection from bugs due to not storing an
 # external reference to an object, but still requires the user to store
 # their own object references.
@@ -34,10 +34,6 @@ class SleepyPenguin::Kqueue
 
   def __kq_check # :nodoc:
     return if @pid == $$ || @io.closed?
-    unless @io.respond_to?(:autoclose=)
-      raise RuntimeError,
-       "Kqueue is not safe to use without IO#autoclose=, upgrade to Ruby 1.9+"
-    end
 
     # kqueue has (strange) close-on-fork behavior
     objects = @copies.values
diff --git a/test/test_kqueue.rb b/test/test_kqueue.rb
index 6de75f3..ae3203d 100644
--- a/test/test_kqueue.rb
+++ b/test/test_kqueue.rb
@@ -100,5 +100,4 @@ class TestKqueue < Test::Unit::TestCase
   ensure
     [ r1, w1, r2, w2, kq1, kq2 ].compact.each(&:close)
   end
-end if defined?(SleepyPenguin::Kqueue) &&
-       IO.instance_methods.include?(:autoclose=)
+end if defined?(SleepyPenguin::Kqueue)
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-22  1:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22  1:41 [PATCH] kqueue: remove IO#autoclose= and 1.8-related checks Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).