Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • webrick/utils.rb

Parent

Included Modules

WEBrick::Utils::TimeoutHandler

Constants

TimeoutMutex

Public Class Methods

cancel(id) click to toggle source
 
               # File webrick/utils.rb, line 115
def TimeoutHandler.cancel(id)
  TimeoutMutex.synchronize{
    instance.cancel(Thread.current, id)
  }
end
            
new() click to toggle source
 
               # File webrick/utils.rb, line 121
def initialize
  @timeout_info = Hash.new
  Thread.start{
    while true
      now = Time.now
      @timeout_info.each{|thread, ary|
        ary.dup.each{|info|
          time, exception = *info
          interrupt(thread, info.object_id, exception) if time < now
        }
      }
      sleep 0.5
    end
  }
end
            
register(seconds, exception) click to toggle source
 
               # File webrick/utils.rb, line 109
def TimeoutHandler.register(seconds, exception)
  TimeoutMutex.synchronize{
    instance.register(Thread.current, Time.now + seconds, exception)
  }
end
            

Public Instance Methods

cancel(thread, id) click to toggle source
 
               # File webrick/utils.rb, line 151
def cancel(thread, id)
  if ary = @timeout_info[thread]
    ary.delete_if{|info| info.object_id == id }
    if ary.empty?
      @timeout_info.delete(thread)
    end
    return true
  end
  return false
end
            
interrupt(thread, id, exception) click to toggle source
 
               # File webrick/utils.rb, line 137
def interrupt(thread, id, exception)
  TimeoutMutex.synchronize{
    if cancel(thread, id) && thread.alive?
      thread.raise(exception, "execution timeout")
    end
  }
end
            
register(thread, time, exception) click to toggle source
 
               # File webrick/utils.rb, line 145
def register(thread, time, exception)
  @timeout_info[thread] ||= Array.new
  @timeout_info[thread] << [time, exception]
  return @timeout_info[thread].last.object_id
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus