- if @sendq_delay > 0
- @qmutex.synchronize do
- @sendq.push msg, chan, ring
- @timer.start
- end
- else
- # just send it if queueing is disabled
- self.emergency_puts(msg)
- end
- end
-
- # pop a message off the queue, send it
- def spool
- @qmutex.synchronize do
- begin
- debug "in spooler"
- if @sendq.empty?
- @timer.stop
- return
- end
- now = Time.new
- if (now >= (@last_send + @sendq_delay))
- debug "resetting @burst"
- @burst = 0
- elsif (@burst > @sendq_burst)
- # nope. can't send anything, come back to us next tick...
- debug "can't send yet"
- @timer.start
- return
- end
- @flood_send = now if @flood_send < now
- debug "can send #{@sendq_burst - @burst} lines, there are #{@sendq.length} to send"
- while !@sendq.empty? and @burst < @sendq_burst and @flood_send - now < MAX_IRC_SEND_PENALTY
- debug "sending message (#{@flood_send - now} < #{MAX_IRC_SEND_PENALTY})"
- puts_critical(@sendq.shift, true)
- end
- if @sendq.empty?
- @timer.stop
- end
- rescue => e
- error "Spooling failed: #{e.inspect}"
- error e.backtrace.join("\n")
- end
- end