From 58c38861d6cb540e5a4239bc2d88df3865ffe1c8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 22 Mar 2017 01:38:30 +0000 Subject: kqueue: remove IO#autoclose= and 1.8-related checks 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) -- cgit v1.2.3-24-ge0c7