Not everybody needs to serve or even buffer to regular files,
so make sendfile optional to avoid the extra memory use and
relocations.
---
 lib/yahns/wbuf_common.rb | 7 ++++---
 yahns.gemspec            | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/yahns/wbuf_common.rb b/lib/yahns/wbuf_common.rb
index 69fd00d..0ce4526 100644
--- a/lib/yahns/wbuf_common.rb
+++ b/lib/yahns/wbuf_common.rb
@@ -1,10 +1,11 @@
 # -*- encoding: binary -*-
 # Copyright (C) 2009-2013, Eric Wong <normalper...@yhbt.net> et. al.
 # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
-if ENV["SENDFILE_BROKEN"]
-  require_relative 'sendfile_compat'
-else
+begin
+  raise LoadError, "SENDFILE_BROKEN env set" if ENV["SENDFILE_BROKEN"]
   require 'sendfile'
+rescue LoadError
+  require_relative 'sendfile_compat'
 end
 
 module Yahns::WbufCommon # :nodoc:
diff --git a/yahns.gemspec b/yahns.gemspec
index db1d50e..120dc46 100644
--- a/yahns.gemspec
+++ b/yahns.gemspec
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
   s.files = manifest
   s.add_dependency(%q<kgio>, '~> 2.9')
   s.add_dependency(%q<sleepy_penguin>, '~> 3.2')
-  s.add_dependency(%q<kgio-sendfile>, '~> 1.2')
   s.add_dependency(%q<unicorn>, '~> 4.6', '>= 4.6.3')
+  # s.add_dependency(%q<kgio-sendfile>, '~> 1.2') # optional
 
   # minitest is standard in Ruby 2.0, 4.3 is packaged with Ruby 2.0.0,
   # 4.7.5 with 2.1.  We work with minitest 5, too.  6.x does not exist
-- 
EW


Reply via email to