<commit_before>require 'socket'
require 'thread'

class SyslogDaemon
  attr_reader :port

  def initialize(port)
    @port = port
    @queue = Queue.new
    @server = TCPServer.new(port)
    @packets = []
    @thread = Thread.new do
      loop do
        client = @server.accept
        while message = client.gets
          @queue << message
        end
      end
    end
  end

  def close
    @server.close
  end

  def address
    "localhost:#{port}"
  end

  def packets
    read_packets!
    @packets
  end

  private

  def read_packets!
    loop do
      sleep 0.01
      break if @queue.empty?
      packet = SyslogProtocol.parse(@queue.pop)
      @packets << packet
    end
  end
end<commit_msg>Don't close the server if it's already closed<commit_after>require 'socket'
require 'thread'

class SyslogDaemon
  attr_reader :port

  def initialize(port)
    @port = port
    @queue = Queue.new
    @server = TCPServer.new(port)
    @packets = []
    @thread = Thread.new do
      loop do
        client = @server.accept
        while message = client.gets
          @queue << message
        end
      end
    end
  end

  def close
    @server.close unless @server.closed?
  end

  def address
    "localhost:#{port}"
  end

  def packets
    read_packets!
    @packets
  end

  private

  def read_packets!
    loop do
      sleep 0.01
      break if @queue.empty?
      packet = SyslogProtocol.parse(@queue.pop)
      @packets << packet
    end
  end
end
{'fraction_non_alphanumeric': 0.08395904436860069, 'fraction_numerical': 0.004095563139931741, 'mean_word_length': 2.086315789473684, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '2059528', 'n_tokens_mistral': 488, 'n_tokens_neox': 467, 'n_words': 134}