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

lib/*: use monotonic clock for timeouts

The monotonic clock is preferred as it is guaranteed to be
continuous and not subject to jumps due to adjustments.

* lib/net/resolv.rb (request): use monotonic clock
* lib/net/http.rb (begin_transport, end_transport): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-05-29 01:40:26 +00:00
parent c1b35ab11e
commit 16aeffefa2
3 changed files with 10 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Fri May 29 10:30:34 2015 Eric Wong <e@80x24.org>
* lib/net/resolv.rb (request): use monotonic clock
* lib/net/http.rb (begin_transport, end_transport): ditto
Fri May 29 04:37:38 2015 Koichi Sasada <ko1@atdot.net>
* ext/objspace/objspace.c: add two methods to debug internals.

View file

@ -1460,7 +1460,7 @@ module Net #:nodoc:
def begin_transport(req)
if @socket.closed?
connect
elsif @last_communicated && @last_communicated + @keep_alive_timeout < Time.now
elsif @last_communicated && @last_communicated + @keep_alive_timeout < Process.clock_gettime(Process::CLOCK_MONOTONIC)
D 'Conn close because of keep_alive_timeout'
@socket.close
connect
@ -1484,7 +1484,7 @@ module Net #:nodoc:
@socket.close
elsif keep_alive?(req, res)
D 'Conn keep-alive'
@last_communicated = Time.now
@last_communicated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
else
D 'Conn close'
@socket.close

View file

@ -667,7 +667,7 @@ class Resolv
end
def request(sender, tout)
start = Time.now
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
timelimit = start + tout
begin
sender.send
@ -676,7 +676,7 @@ class Resolv
raise ResolvTimeout
end
while true
before_select = Time.now
before_select = Process.clock_gettime(Process::CLOCK_MONOTONIC)
timeout = timelimit - before_select
if timeout <= 0
raise ResolvTimeout
@ -687,7 +687,7 @@ class Resolv
select_result = IO.select(@socks, nil, nil, timeout)
end
if !select_result
after_select = Time.now
after_select = Process.clock_gettime(Process::CLOCK_MONOTONIC)
next if after_select < timelimit
raise ResolvTimeout
end