Skip to content

Commit

Permalink
* lib/timeout.rb (timeout): new optional argument to specify an
Browse files Browse the repository at this point in the history
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
  • Loading branch information
akr committed Jan 16, 2002
1 parent 5fe2879 commit 17e1cfe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Wed Jan 16 12:29:14 2002 Tanaka Akira <[email protected]>

* 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 <[email protected]>

* object.c (rb_Float): remove underscores between digits.
Expand Down
7 changes: 5 additions & 2 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ def each_name(address)
class ResolvError < StandardError
end

class ResolvTimeout < TimeoutError
end

class Hosts
DefaultFileName = '/etc/hosts'

Expand Down Expand Up @@ -426,7 +429,7 @@ def each_resource(name, typeclass, &proc)
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)
Expand Down Expand Up @@ -753,7 +756,7 @@ def resolv(name)
@nameserver.each {|nameserver|
begin
yield candidate, tout, nameserver
rescue TimeoutError
rescue ResolvTimeout
end
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17e1cfe

Please sign in to comment.