Feature #11124 ยป 0001-lib-use-monotonic-clock-for-timeouts.patch
| lib/net/http.rb | ||
|---|---|---|
|
raise exception
|
||
|
end
|
||
|
if defined?(Process::CLOCK_MONOTONIC)
|
||
|
def now
|
||
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||
|
end
|
||
|
else
|
||
|
def now
|
||
|
Process.clock_gettime(Process::CLOCK_REALTIME)
|
||
|
end
|
||
|
end
|
||
|
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 < now
|
||
|
D 'Conn close because of keep_alive_timeout'
|
||
|
@socket.close
|
||
|
connect
|
||
| ... | ... | |
|
@socket.close
|
||
|
elsif keep_alive?(req, res)
|
||
|
D 'Conn keep-alive'
|
||
|
@last_communicated = Time.now
|
||
|
@last_communicated = now
|
||
|
else
|
||
|
D 'Conn close'
|
||
|
@socket.close
|
||
| lib/resolv.rb | ||
|---|---|---|
|
@socks = nil
|
||
|
end
|
||
|
if defined?(Process::CLOCK_MONOTONIC)
|
||
|
def now
|
||
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||
|
end
|
||
|
else
|
||
|
def now
|
||
|
Process.clock_gettime(Process::CLOCK_REALTIME)
|
||
|
end
|
||
|
end
|
||
|
def request(sender, tout)
|
||
|
start = Time.now
|
||
|
start = now
|
||
|
timelimit = start + tout
|
||
|
begin
|
||
|
sender.send
|
||
| ... | ... | |
|
raise ResolvTimeout
|
||
|
end
|
||
|
while true
|
||
|
before_select = Time.now
|
||
|
before_select = now
|
||
|
timeout = timelimit - before_select
|
||
|
if timeout <= 0
|
||
|
raise ResolvTimeout
|
||
| ... | ... | |
|
select_result = IO.select(@socks, nil, nil, timeout)
|
||
|
end
|
||
|
if !select_result
|
||
|
after_select = Time.now
|
||
|
after_select = now
|
||
|
next if after_select < timelimit
|
||
|
raise ResolvTimeout
|
||
|
end
|
||
|
-
|
||