def start_server_pings
stop_server_pings
return unless @config['server.ping_timeout'] > 0
@ping_timer = @timer.add(30) {
@last_ping = Time.now
@socket.queue "PING :rbot"
}
@pong_timer = @timer.add(10) {
unless @last_ping.nil?
diff = Time.now - @last_ping
unless diff < @config['server.ping_timeout']
debug "no PONG from server for #{diff} seconds, reconnecting"
begin
@socket.shutdown
rescue
debug "couldn't shutdown connection (already shutdown?)"
end
@last_ping = nil
raise TimeoutError, "no PONG from server in #{diff} seconds"
end
end
}
end