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)
debug "can't send yet"
@timer.start
return
end
debug "can send #{@sendq_burst - @burst} lines, there are #{@sendq.length} to send"
(@sendq_burst - @burst).times do
break if @sendq.empty?
mess = @sendq.next
if @throttle_bytes == 0 or mess.length+@throttle_bytes < @bytes_per
debug "flood protection: sending message of length #{mess.length}"
debug "(byterate: #{byterate}, throttle bytes: #{@throttle_bytes})"
puts_critical(@sendq.shift)
else
debug "flood protection: throttling message of length #{mess.length}"
debug "(byterate: #{byterate}, throttle bytes: #{@throttle_bytes})"
run_throttle
break
end
end
if @sendq.empty?
@timer.stop
end
rescue => e
error "Spooling failed: #{e.inspect}"
error e.backtrace.join("\n")
end
end
end