From b365d31ff14c8899eea84e60f25792c970a70d99 Mon Sep 17 00:00:00 2001 From: Eric Will Date: Sun, 19 Sep 2010 02:38:29 -0400 Subject: [PATCH] Fix an issue in the event code (from rhuidean). Allow the same event to be posted more than once to the same queue. If this is done it can allow things like two "this socket is ready to be read from" events to be posted and result in two calls to read(), one of which will wind up blocking. This is bad. However, NOT allowing this results in worse things, like if a certain event-triggering data comes in more than once in a single read()/event loop it results it it only being processed once and will ignore the rest. This is unacceptable. Since the former can be corrected with good coding, and the latter cannot, then the former loses (thanks sycobuny). --- lib/kintara/event.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/kintara/event.rb b/lib/kintara/event.rb index a477f25..ff75cd1 100644 --- a/lib/kintara/event.rb +++ b/lib/kintara/event.rb @@ -48,18 +48,18 @@ def initialize ## # Post a new event to the queue to be handled. + # Events can be posted more than once per loop, + # so the callers need to make sure calling the + # same handlers twice for the same run isn't going + # to bork something serious like make an otherwise + # good call become blocking (like read). # --- # event:: event name as a Symbol # args:: list of arguments to pass to handler # returns:: +self+ # def post(event, *args) - # Only one post per event per loop, otherwise we end up trying - # to read from a socket that has no data, or stuff like that. - return if m = @queue.find { |q| q.event == event } - @queue << Event.new(event, *args) - self end