summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-16 03:37:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-16 03:37:23 +0000
commit17e1cfef8cae430ecce87ea3338b29992bd12665 (patch)
treefc3d9a3b547bcab1a95ff2fa64c58b0c4c7cd5f0
parent5fe2879fd5b2b5db264f4bdbbc1181482b70e339 (diff)
* 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
-rw-r--r--ChangeLog8
-rw-r--r--lib/resolv.rb7
-rw-r--r--lib/timeout.rb4
3 files changed, 15 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 633cd9dfe6..1d90e24780 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* object.c (rb_Float): remove underscores between digits.
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 4c95826653..bfe8dd8b61 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -258,6 +258,9 @@ class Resolv
class ResolvError < StandardError
end
+ class ResolvTimeout < TimeoutError
+ end
+
class Hosts
DefaultFileName = '/etc/hosts'
@@ -426,7 +429,7 @@ class Resolv
end
sender.send
reply = reply_name = nil
- timeout(tout) { reply, reply_name = q.pop }
+ timeout(tout, ResolvTimeout) { reply, reply_name = q.pop }
case reply.rcode
when RCode::NoError
extract_resources(reply, reply_name, typeclass, &proc)
@@ -753,7 +756,7 @@ class Resolv
@nameserver.each {|nameserver|
begin
yield candidate, tout, nameserver
- rescue TimeoutError
+ rescue ResolvTimeout
end
}
}
diff --git a/lib/timeout.rb b/lib/timeout.rb
index afa4e0b68c..8c6ccb7128 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -28,13 +28,13 @@
class TimeoutError<Interrupt
end
-def timeout(sec)
+def timeout(sec, exception=TimeoutError)
return yield if sec == nil
begin
x = Thread.current
y = Thread.start {
sleep sec
- x.raise TimeoutError, "execution expired" if x.alive?
+ x.raise exception, "execution expired" if x.alive?
}
yield sec
# return true