This class manages all outgoing messages, applying rate throttling and fair distribution.
@api private
@return [void]
# File lib/cinch/message_queue.rb, line 54 def process! while true wait queue = @queues_to_process.pop message = queue.pop.to_s.chomp if queue.empty? @mutex.synchronize do @queued_queues.delete(queue) end else @queues_to_process << queue end begin to_send = Cinch::Utilities::Encoding.encode_outgoing(message, @bot.config.encoding) @socket.write to_send + "\r\n" @log << Time.now @bot.loggers.outgoing(message) @time_since_last_send = Time.now rescue IOError @bot.loggers.error "Could not send message (connectivity problems): #{message}" end end end
@return [void]
# File lib/cinch/message_queue.rb, line 24 def queue(message) command, *rest = message.split(" ") queue = nil case command when "PRIVMSG", "NOTICE" @mutex.synchronize do # we are assuming that each message has only one target, # which will be true as long as the user does not send raw # messages. # # this assumption is also reflected in the computation of # passed time and processed messages, since our score does # not take weights into account. queue = @queues[rest.first] ||= OpenEndedQueue.new end else queue = @queues[:generic] end queue << message @mutex.synchronize do unless @queued_queues.include?(queue) @queued_queues << queue @queues_to_process << queue end end end
Generated with the Darkfish Rdoc Generator 2.