<commit_before>module Net; module SSH; module Connection

module Keepalive
  # Default IO.select timeout threshold
  DEFAULT_IO_SELECT_TIMEOUT = 300

  def initialize_keepalive
    @last_keepalive_sent_at = nil
    @unresponded_keepalive_count = 0
  end

  def keepalive_enabled?
    options[:keepalive]
  end

  def keepalive_interval
    options[:keepalive_interval] || DEFAULT_IO_SELECT_TIMEOUT
  end

  def should_send_keepalive?
    return false unless keepalive_enabled?
    return true unless @last_keepalive_sent_at
    Time.now - @last_keepalive_sent_at >= keepalive_interval
  end

  def keepalive_maxcount
    (options[:keepalive_maxcount] || 3).to_i
  end

  def send_keepalive_as_needed(readers, writers)
    return unless readers.nil? && writers.nil?
    return unless should_send_keepalive?
    info { "sending keepalive #{@unresponded_keepalive_count}" }

    @unresponded_keepalive_count += 1
    send_global_request("<EMAIL>") { |success, response|
      @unresponded_keepalive_count = 0
    }
    if keepalive_maxcount > 0 && @unresponded_keepalive_count > keepalive_maxcount
      error { "Timeout, server #{host} not responding. Missed #{@unresponded_keepalive_count} timeouts." }
      raise Net::SSH::Timeout, "Timeout, server #{host} not responding."
    end
    @last_keepalive_sent_at = Time.now
  end
end

end; end; end<commit_msg>timeout_maxcount: Since we've just sent out a message do not count that as missed<commit_after>module Net; module SSH; module Connection

module Keepalive
  # Default IO.select timeout threshold
  DEFAULT_IO_SELECT_TIMEOUT = 300

  def initialize_keepalive
    @last_keepalive_sent_at = nil
    @unresponded_keepalive_count = 0
  end

  def keepalive_enabled?
    options[:keepalive]
  end

  def keepalive_interval
    options[:keepalive_interval] || DEFAULT_IO_SELECT_TIMEOUT
  end

  def should_send_keepalive?
    return false unless keepalive_enabled?
    return true unless @last_keepalive_sent_at
    Time.now - @last_keepalive_sent_at >= keepalive_interval
  end

  def keepalive_maxcount
    (options[:keepalive_maxcount] || 3).to_i
  end

  def send_keepalive_as_needed(readers, writers)
    return unless readers.nil? && writers.nil?
    return unless should_send_keepalive?
    info { "sending keepalive #{@unresponded_keepalive_count}" }

    @unresponded_keepalive_count += 1
    send_global_request("<EMAIL>") { |success, response|
      puts "before zero => #{@unresponded_keepalive_count}"
      @unresponded_keepalive_count = 0
    }
    if keepalive_maxcount > 0 && @unresponded_keepalive_count > keepalive_maxcount
      error { "Timeout, server #{host} not responding. Missed #{@unresponded_keepalive_count-1} timeouts." }
      raise Net::SSH::Timeout, "Timeout, server #{host} not responding."
    end
    @last_keepalive_sent_at = Time.now
  end
end

end; end; end
{'fraction_non_alphanumeric': 0.07905832747716093, 'fraction_numerical': 0.0059732958538299364, 'mean_word_length': 4.371698113207547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6020335', 'n_tokens_mistral': 971, 'n_tokens_neox': 942, 'n_words': 214}