about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-05 21:03:53 +0000
committerEric Wong <e@80x24.org>2019-01-05 21:03:53 +0000
commit38cdd06ca624f5b1b6f874724c88976cf8398367 (patch)
treee892762e74c85d0426fe551db6f2ac4cc84fb37d
parentadd2edafb14f72788823af2707d457357f717983 (diff)
downloadyahns-38cdd06ca624f5b1b6f874724c88976cf8398367.tar.gz
Slowly removing kgio dependencies...
-rw-r--r--lib/yahns/wbuf.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index 3abc5f9..d3552b3 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -31,6 +31,7 @@ require_relative 'wbuf_common'
 class Yahns::Wbuf # :nodoc:
   include Yahns::WbufCommon
   attr_reader :busy
+  IO_WRITEV = RUBY_VERSION.to_r >= 2.5 # IO#write uses writev
 
   def initialize(body, persist)
     @tmpio = nil
@@ -40,9 +41,15 @@ class Yahns::Wbuf # :nodoc:
     @busy = false
   end
 
-  def wbuf_writev(buf)
-    @tmpio.kgio_writev(buf)
-    buf.inject(0) { |n, s| n += s.size }
+  if IO_WRITEV
+    def wbuf_writev(buf)
+      @tmpio.write(*buf)
+    end
+  else
+    def wbuf_writev(buf)
+      @tmpio.kgio_writev(buf)
+      buf.inject(0) { |n, s| n += s.size }
+    end
   end
 
   def wbuf_write(c, buf)