1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
normal 2016-10-14 01:48:52 +00:00
parent 34d420acc4
commit 1fc0c08694
2 changed files with 8 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Fri Oct 14 10:48:37 2016 Eric Wong <e@80x24.org>
* lib/webrick/utils.rb (TimeoutHandler): use monotonic clock
(watch): ditto
Thu Oct 13 19:41:32 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (copy_stream_body): use IO to write to copy to duplex IO.

View file

@ -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{