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:
parent
c1b35ab11e
commit
16aeffefa2
@ -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>
|
Fri May 29 04:37:38 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* ext/objspace/objspace.c: add two methods to debug internals.
|
* ext/objspace/objspace.c: add two methods to debug internals.
|
||||||
|
@ -1460,7 +1460,7 @@ module Net #:nodoc:
|
|||||||
def begin_transport(req)
|
def begin_transport(req)
|
||||||
if @socket.closed?
|
if @socket.closed?
|
||||||
connect
|
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'
|
D 'Conn close because of keep_alive_timeout'
|
||||||
@socket.close
|
@socket.close
|
||||||
connect
|
connect
|
||||||
@ -1484,7 +1484,7 @@ module Net #:nodoc:
|
|||||||
@socket.close
|
@socket.close
|
||||||
elsif keep_alive?(req, res)
|
elsif keep_alive?(req, res)
|
||||||
D 'Conn keep-alive'
|
D 'Conn keep-alive'
|
||||||
@last_communicated = Time.now
|
@last_communicated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
else
|
else
|
||||||
D 'Conn close'
|
D 'Conn close'
|
||||||
@socket.close
|
@socket.close
|
||||||
|
@ -667,7 +667,7 @@ class Resolv
|
|||||||
end
|
end
|
||||||
|
|
||||||
def request(sender, tout)
|
def request(sender, tout)
|
||||||
start = Time.now
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
timelimit = start + tout
|
timelimit = start + tout
|
||||||
begin
|
begin
|
||||||
sender.send
|
sender.send
|
||||||
@ -676,7 +676,7 @@ class Resolv
|
|||||||
raise ResolvTimeout
|
raise ResolvTimeout
|
||||||
end
|
end
|
||||||
while true
|
while true
|
||||||
before_select = Time.now
|
before_select = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
timeout = timelimit - before_select
|
timeout = timelimit - before_select
|
||||||
if timeout <= 0
|
if timeout <= 0
|
||||||
raise ResolvTimeout
|
raise ResolvTimeout
|
||||||
@ -687,7 +687,7 @@ class Resolv
|
|||||||
select_result = IO.select(@socks, nil, nil, timeout)
|
select_result = IO.select(@socks, nil, nil, timeout)
|
||||||
end
|
end
|
||||||
if !select_result
|
if !select_result
|
||||||
after_select = Time.now
|
after_select = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
next if after_select < timelimit
|
next if after_select < timelimit
|
||||||
raise ResolvTimeout
|
raise ResolvTimeout
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user