about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-11-01 00:05:14 +0000
committerEric Wong <normalperson@yhbt.net>2013-11-01 00:05:14 +0000
commitfebabe3dcfd1ee41cc253ca43fd667c9e2ec6444 (patch)
tree20c2e1eb7be0c81fdd86b38d8e18fb79aebf461a
parent7c32323bdd375b1167b42991c081e3b579ad8243 (diff)
downloadyahns-febabe3dcfd1ee41cc253ca43fd667c9e2ec6444.tar.gz
Some users may care to have sub-second or fractional timeouts for
various reasons.  Do not reject those values to be consistent with
Ruby sleep/select.
-rw-r--r--lib/yahns/config.rb14
-rw-r--r--test/test_client_expire.rb2
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/yahns/config.rb b/lib/yahns/config.rb
index 29f5746..1862eee 100644
--- a/lib/yahns/config.rb
+++ b/lib/yahns/config.rb
@@ -76,7 +76,7 @@ class Yahns::Config # :nodoc:
 
   def shutdown_timeout(sec)
     var = _check_in_block(nil, :shutdown_timeout)
-    @set[var] = _check_int(var, sec, 0)
+    @set[var] = _check_num(var, sec, 0)
   end
 
   def worker_processes(nr, &blk)
@@ -283,6 +283,12 @@ class Yahns::Config # :nodoc:
     n
   end
 
+  def _check_num(var, n, min)
+    Numeric === n or raise ArgumentError, "not a number: #{var}=#{n.inspect}"
+    n >= min or raise ArgumentError, "too low (< #{min}): #{var}=#{n.inspect}"
+    n
+  end
+
   # global
   def client_expire_threshold(val)
     var = _check_in_block(nil, :client_expire_threshold)
@@ -345,7 +351,6 @@ class Yahns::Config # :nodoc:
     client_body_buffer_size: 1,
     client_header_buffer_size: 1,
     client_max_header_size: 1,
-    client_timeout: 0,
   }.each do |_v,minval|
     eval(
     %Q(def #{_v}(val);) <<
@@ -355,6 +360,11 @@ class Yahns::Config # :nodoc:
     )
   end
 
+  def client_timeout(val)
+    var = _check_in_block(:app, :client_timeout)
+    @block.ctx.__send__("#{var}=", _check_num(var, val, 0))
+  end
+
   def client_max_body_size(val)
     var = _check_in_block(:app, :client_max_body_size)
     val = _check_int(var, val, 0) if val != nil
diff --git a/test/test_client_expire.rb b/test/test_client_expire.rb
index bff00cb..6436c7c 100644
--- a/test/test_client_expire.rb
+++ b/test/test_client_expire.rb
@@ -87,7 +87,7 @@ class TestClientExpire < Testcase
         }
         app(:rack, ru) do
           listen "#{host}:#{port}", sndbuf: 2048, rcvbuf: 2048
-          client_timeout 1
+          client_timeout 1.0
           # FIXME: wbuf creation does not recover from EMFILE/ENFILE
           output_buffering false
           check_client_connection true