yahns Ruby server user/dev discussion
 help / color / Atom feed
* [PATCH] wbuf: use IO#write directly in Ruby 2.5+ for writev
@ 2019-01-05 21:04 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-01-05 21:04 UTC (permalink / raw)
  To: yahns-public

Slowly removing kgio dependencies...
---
 lib/yahns/wbuf.rb | 13 ++++++++++---
 1 file 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 @@
 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 @@ def initialize(body, persist)
     @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)
-- 
EW


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

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-05 21:04 [PATCH] wbuf: use IO#write directly in Ruby 2.5+ for writev Eric Wong

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox