mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/timeout.rb (timeout): new optional argument to specify an
exception class. * lib/resolv.rb: use Resolv::ResolvTimeout for internal timeout to avoid problem with timeout of application. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5fe2879fd5
commit
17e1cfef8c
3 changed files with 15 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Wed Jan 16 12:29:14 2002 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/timeout.rb (timeout): new optional argument to specify an
|
||||||
|
exception class.
|
||||||
|
|
||||||
|
* lib/resolv.rb: use Resolv::ResolvTimeout for internal timeout to
|
||||||
|
avoid problem with timeout of application.
|
||||||
|
|
||||||
Wed Jan 16 11:12:30 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
Wed Jan 16 11:12:30 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
* object.c (rb_Float): remove underscores between digits.
|
* object.c (rb_Float): remove underscores between digits.
|
||||||
|
|
|
@ -258,6 +258,9 @@ class Resolv
|
||||||
class ResolvError < StandardError
|
class ResolvError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ResolvTimeout < TimeoutError
|
||||||
|
end
|
||||||
|
|
||||||
class Hosts
|
class Hosts
|
||||||
DefaultFileName = '/etc/hosts'
|
DefaultFileName = '/etc/hosts'
|
||||||
|
|
||||||
|
@ -426,7 +429,7 @@ class Resolv
|
||||||
end
|
end
|
||||||
sender.send
|
sender.send
|
||||||
reply = reply_name = nil
|
reply = reply_name = nil
|
||||||
timeout(tout) { reply, reply_name = q.pop }
|
timeout(tout, ResolvTimeout) { reply, reply_name = q.pop }
|
||||||
case reply.rcode
|
case reply.rcode
|
||||||
when RCode::NoError
|
when RCode::NoError
|
||||||
extract_resources(reply, reply_name, typeclass, &proc)
|
extract_resources(reply, reply_name, typeclass, &proc)
|
||||||
|
@ -753,7 +756,7 @@ class Resolv
|
||||||
@nameserver.each {|nameserver|
|
@nameserver.each {|nameserver|
|
||||||
begin
|
begin
|
||||||
yield candidate, tout, nameserver
|
yield candidate, tout, nameserver
|
||||||
rescue TimeoutError
|
rescue ResolvTimeout
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@
|
||||||
class TimeoutError<Interrupt
|
class TimeoutError<Interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
def timeout(sec)
|
def timeout(sec, exception=TimeoutError)
|
||||||
return yield if sec == nil
|
return yield if sec == nil
|
||||||
begin
|
begin
|
||||||
x = Thread.current
|
x = Thread.current
|
||||||
y = Thread.start {
|
y = Thread.start {
|
||||||
sleep sec
|
sleep sec
|
||||||
x.raise TimeoutError, "execution expired" if x.alive?
|
x.raise exception, "execution expired" if x.alive?
|
||||||
}
|
}
|
||||||
yield sec
|
yield sec
|
||||||
# return true
|
# return true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue