yahns Ruby server user/dev discussion
 help / color / Atom feed
* [PATCH] remove calls to kgio_wait_* able
@ 2019-01-07 10:43 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-01-07 10:43 UTC (permalink / raw)
  To: yahns-public

IO#wait_readable existed since Ruby 2.0, so we don't need
to use the "kgio_"-prefixed version.
---
 extras/proxy_pass.rb       |  4 ++--
 lib/yahns.rb               |  1 +
 lib/yahns/http_client.rb   | 16 ++++------------
 lib/yahns/http_response.rb |  5 ++---
 lib/yahns/server.rb        |  2 +-
 lib/yahns/server_mp.rb     |  2 +-
 lib/yahns/sigevent_pipe.rb |  4 ----
 7 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/extras/proxy_pass.rb b/extras/proxy_pass.rb
index 310da9e..af6fe01 100644
--- a/extras/proxy_pass.rb
+++ b/extras/proxy_pass.rb
@@ -36,7 +36,7 @@ class UpstreamSocket < Kgio::Socket # :nodoc:
     attr_writer :expiry
 
     # called automatically by kgio_read!
-    def kgio_wait_readable(timeout = nil)
+    def wait_readable(timeout = nil)
       super(timeout || wait_time)
     end
 
@@ -59,7 +59,7 @@ def req_write(buf, timeout)
       @expiry = Time.now + timeout
       case rv = kgio_trywrite(buf)
       when :wait_writable
-        kgio_wait_writable(wait_time)
+        wait_writable(wait_time)
       when nil
         return
       when String
diff --git a/lib/yahns.rb b/lib/yahns.rb
index a0abe49..21464ca 100644
--- a/lib/yahns.rb
+++ b/lib/yahns.rb
@@ -5,6 +5,7 @@
 
 require 'unicorn' # pulls in raindrops, kgio, fcntl, etc, stringio, and logger
 require 'sleepy_penguin'
+require 'io/wait'
 
 # kill off some unicorn internals we don't need
 # we'll probably just make kcar into a server parser so we don't depend
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index 8744053..b6b6035 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -235,25 +235,17 @@ def app_call(input)
     http_response_write(res, opt)
   end
 
-  # called automatically by kgio_write
-  def kgio_wait_writable(timeout = self.class.client_timeout)
-    super timeout
-  end
-
-  # called automatically by kgio_read
-  def kgio_wait_readable(timeout = self.class.client_timeout)
-    super timeout
-  end
-
   # used by StreamInput (and thus TeeInput) for input_buffering {false|:lazy}
   def yahns_read(bytes, buf)
     case rv = kgio_tryread(bytes, buf)
     when String, nil
       return rv
     when :wait_readable
-      kgio_wait_readable or raise Yahns::ClientTimeout, "waiting for read", []
+      wait_readable(self.class.client_timeout) or
+        raise Yahns::ClientTimeout, "waiting for read", []
     when :wait_writable
-      kgio_wait_writable or raise Yahns::ClientTimeout, "waiting for write", []
+      wait_writable(self.class.client_timeout) or
+        raise Yahns::ClientTimeout, "waiting for write", []
     end while true
   end
 
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index 865193d..2e719eb 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -46,10 +46,9 @@ def response_start
     @hs.response_start_sent ? ''.freeze : 'HTTP/1.1 '.freeze
   end
 
-  def response_wait_write(rv)
-    # call the kgio_wait_readable or kgio_wait_writable method
-    ok = __send__("kgio_#{rv}") and return ok
+  def response_wait_write(rv) # rv = [:wait_writable | :wait_readable ]
     k = self.class
+    ok = __send__(rv, k.client_timeout) and return ok
     k.logger.info("fd=#{fileno} ip=#@kgio_addr timeout on :#{rv} after "\
                   "#{k.client_timeout}s")
     false
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index 2ad65a9..c078ade 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -476,7 +476,7 @@ def reap_reexec
   end
 
   def sp_sig_handle(alive)
-    @sev.kgio_wait_readable(alive ? nil : 0.01)
+    @sev.wait_readable(alive ? nil : 0.01)
     @sev.yahns_step
     case sig = @sig_queue.shift
     when :QUIT, :TERM, :INT
diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb
index 8752a08..5467674 100644
--- a/lib/yahns/server_mp.rb
+++ b/lib/yahns/server_mp.rb
@@ -89,7 +89,7 @@ def join
     @logger.info "master process ready"
     daemon_ready
     begin
-      @sev.kgio_wait_readable
+      @sev.wait_readable
       @sev.yahns_step
       reap_all
       case @sig_queue.shift
diff --git a/lib/yahns/sigevent_pipe.rb b/lib/yahns/sigevent_pipe.rb
index f630e72..df4c31a 100644
--- a/lib/yahns/sigevent_pipe.rb
+++ b/lib/yahns/sigevent_pipe.rb
@@ -8,10 +8,6 @@ def initialize
     @to_io, @wr = Kgio::Pipe.new
   end
 
-  def kgio_wait_readable(*args)
-    @to_io.kgio_wait_readable(*args)
-  end
-
   def sev_signal
     @wr.kgio_trywrite(".")
   end
-- 
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-07 10:43 [PATCH] remove calls to kgio_wait_* able 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

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