1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
module WEBrick
module Utils
#
# Sets IO operations on +io+ to be non-blocking
def self?.set_non_blocking: (IO io) -> void
#
# Sets the close on exec flag for +io+
def self?.set_close_on_exec: (IO io) -> void
#
# Changes the process's uid and gid to the ones of +user+
def self?.su: (String user) -> void
#
# The server hostname
def self?.getservername: () -> String
#
# Creates TCP server sockets bound to +address+:+port+ and returns them.
#
# It will create IPV4 and IPV6 sockets on all interfaces.
def self?.create_listeners: (String host, Integer port) -> Array[TCPServer]
#
# Characters used to generate random strings
RAND_CHARS: String
#
# Generates a random string of length +len+
def self?.random_string: (Integer len) -> String
#
# Class used to manage timeout handlers across multiple threads.
#
# Timeout handlers should be managed by using the class methods which are
# synchronized.
#
# id = TimeoutHandler.register(10, Timeout::Error)
# begin
# sleep 20
# puts 'foo'
# ensure
# TimeoutHandler.cancel(id)
# end
#
# will raise Timeout::Error
#
# id = TimeoutHandler.register(10, Timeout::Error)
# begin
# sleep 5
# puts 'foo'
# ensure
# TimeoutHandler.cancel(id)
# end
#
# will print 'foo'
#
class TimeoutHandler
@queue: Thread::Queue
@watcher: Thread?
include Singleton
#
# Mutex used to synchronize access across threads
TimeoutMutex: Thread::Mutex
#
# Registers a new timeout handler
#
# +time+:: Timeout in seconds
# +exception+:: Exception to raise when timeout elapsed
def self.register: (Numeric seconds, singleton(Exception) exception) -> Integer
#
# Cancels the timeout handler +id+
def self.cancel: (Integer id) -> bool
def self.terminate: () -> Thread?
#
# Creates a new TimeoutHandler. You should use ::register and ::cancel
# instead of creating the timeout handler directly.
def initialize: () -> void
private
def watch: () -> bot
def watcher: () -> Thread
public
#
# Interrupts the timeout handler +id+ and raises +exception+
def interrupt: (Thread thread, Integer id, singleton(Exception) exception) -> nil
#
# Registers a new timeout handler
#
# +time+:: Timeout in seconds
# +exception+:: Exception to raise when timeout elapsed
def register: (Thread thread, Numeric time, singleton(Exception) exception) -> Integer
#
# Cancels the timeout handler +id+
def cancel: (Thread thread, Integer id) -> bool
#
def terminate: () -> Thread?
end
#
# Executes the passed block and raises +exception+ if execution takes more
# than +seconds+.
#
# If +seconds+ is zero or nil, simply executes the block
def self?.timeout: [T] (Numeric? seconds, ?singleton(Exception) exception) { (?Numeric) -> T } -> T
end
end
|