ruby-changes:44345
From: normal <ko1@a...>
Date: Fri, 14 Oct 2016 10:49:27 +0900 (JST)
Subject: [ruby-changes:44345] normal:r56417 (trunk): webrick: use monotonic clock for timeouts
normal 2016-10-14 10:48:52 +0900 (Fri, 14 Oct 2016) New Revision: 56417 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56417 Log: webrick: use monotonic clock for timeouts The monotonic clock is immune to system time changes and a better option for implementing timing comparisons. * lib/webrick/utils.rb (TimeoutHandler): use monotonic clock (watch): ditto Modified files: trunk/ChangeLog trunk/lib/webrick/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 56416) +++ ChangeLog (revision 56417) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Oct 14 10:48:37 2016 Eric Wong <e@8...> + + * lib/webrick/utils.rb (TimeoutHandler): use monotonic clock + (watch): ditto + Thu Oct 13 19:41:32 2016 Nobuyoshi Nakada <nobu@r...> * io.c (copy_stream_body): use IO to write to copy to duplex IO. Index: lib/webrick/utils.rb =================================================================== --- lib/webrick/utils.rb (revision 56416) +++ lib/webrick/utils.rb (revision 56417) @@ -134,7 +134,8 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L134 # +time+:: Timeout in seconds # +exception+:: Exception to raise when timeout elapsed def TimeoutHandler.register(seconds, exception) - instance.register(Thread.current, Time.now + seconds, exception) + at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + seconds + instance.register(Thread.current, at, exception) end ## @@ -163,7 +164,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L164 def watch to_interrupt = [] while true - now = Time.now + now = Process.clock_gettime(Process::CLOCK_MONOTONIC) wakeup = nil to_interrupt.clear TimeoutMutex.synchronize{ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/