Skip to content

Commit 6509696

Browse files
committed
Switch back to Mutex/CV for response waiters
Makes use of the wait() method's timeout parameter instead of using the Timeout class.
1 parent 640a302 commit 6509696

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/rex/post/meterpreter/packet_response_waiter.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def initialize(rid, completion_routine = nil, completion_param = nil)
2727
self.completion_routine = completion_routine
2828
self.completion_param = completion_param
2929
else
30-
self.done = false
30+
self.mutex = Mutex.new
31+
self.cond = ConditionVariable.new
3132
end
3233
end
3334

@@ -48,7 +49,9 @@ def notify(response)
4849
if (self.completion_routine)
4950
self.completion_routine.call(response, self.completion_param)
5051
else
51-
self.done = true
52+
self.mutex.synchronize {
53+
self.cond.signal
54+
}
5255
end
5356
end
5457

@@ -57,25 +60,14 @@ def notify(response)
5760
# If the interval is -1 we can wait forever.
5861
#
5962
def wait(interval)
60-
if( interval and interval == -1 )
61-
while(not self.done)
62-
::IO.select(nil, nil, nil, 0.1)
63-
end
64-
else
65-
begin
66-
Timeout.timeout(interval) {
67-
while(not self.done)
68-
::IO.select(nil, nil, nil, 0.1)
69-
end
70-
}
71-
rescue Timeout::Error
72-
self.response = nil
73-
end
74-
end
63+
interval = nil if interval and interval == -1
64+
self.mutex.synchronize {
65+
self.cond.wait(self.mutex, interval)
66+
}
7567
return self.response
7668
end
7769

78-
attr_accessor :rid, :done, :response # :nodoc:
70+
attr_accessor :rid, :mutex, :cond, :response # :nodoc:
7971
attr_accessor :completion_routine, :completion_param # :nodoc:
8072
end
8173

0 commit comments

Comments
 (0)