class Rex::Sync::Event
This class wraps the logical ConditionVariable class to make it an easier to work with interface that is similar to Windows' synchronization events.
Constants
- Infinite
Public Class Methods
new(state = false, auto_reset = true, param = nil)
click to toggle source
Initializes a waitable event. The state parameter initializes the default state of the event. If auto_reset is true, any calls to set() will automatically reset the event back to an unset state.
# File lib/rex/sync/event.rb, line 21 def initialize(state = false, auto_reset = true, param = nil) self.state = state self.auto_reset = auto_reset self.param = param self.mutex = Mutex.new self.cond = ConditionVariable.new end
Public Instance Methods
reset()
click to toggle source
Resets the signaled state to false.
# File lib/rex/sync/event.rb, line 49 def reset self.param = nil self.state = false end
set(param = nil)
click to toggle source
Sets the event and wakes up anyone who was waiting.
# File lib/rex/sync/event.rb, line 32 def set(param = nil) self.param = param self.mutex.synchronize { # If this event does not automatically reset its state, # set the state to true if (auto_reset == false) self.state = true end self.cond.broadcast } end
Also aliased as: notify
wait(t = Infinite)
click to toggle source
Waits for the event to become signaled. Timeout is measured in seconds. Raises TimeoutError
if the condition does not become signaled.
# File lib/rex/sync/event.rb, line 63 def wait(t = Infinite) self.mutex.synchronize { break if (self.state == true) Timeout.timeout(t) { self.cond.wait(self.mutex) } } return self.param end