aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webrick
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-14 01:48:52 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-14 01:48:52 +0000
commite51c6e57047bec18b0e844f1bf13026c87114ddf (patch)
tree2b5e0f902bd7cd2e26b0816a37e31a27866e1d08 /lib/webrick
parentce52ba9f3f920f4b5eb366dbc2e94f49e7333220 (diff)
downloadruby-e51c6e57047bec18b0e844f1bf13026c87114ddf.tar.gz
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick')
-rw-r--r--lib/webrick/utils.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index eb3b907ecf..8b34b6654f 100644
--- a/lib/webrick/utils.rb
+++ b/lib/webrick/utils.rb
@@ -134,7 +134,8 @@ module WEBrick
# +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
def watch
to_interrupt = []
while true
- now = Time.now
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
wakeup = nil
to_interrupt.clear
TimeoutMutex.synchronize{