<commit_before>require 'socket'
require "thread"

module FakeFtp
  class ServerQuit < Exception;
  end

  class Server

    attr_accessor :directory, :port

    CMDS = %w[user pass]
    LNBK = "\r\n"

    def initialize(port = 21)
      self.port = port
      @connections = []
      if self.is_running?
        raise "Port in use: #{port}"
      end
    end

    def start
      @status = :starting
      @server = ::TCPServer.new('127.0.0.1', port)
      @thread = Thread.new do
        begin
          while @status != :closed
            @client = @server.accept
            respond_with('200 Can has FTP?')
            @connections << Thread.new(@client) do |socket|
              parse(socket.gets)
            end
          end
        rescue ServerQuit
          @status = :closed
        ensure
          @thread = nil
        end
      end
    end

    def stop
      @status = :closed
      @server.close
      @server = nil
    end

    def is_running?
      service = `lsof -w -n -i tcp:#{port}`
      !service.nil? && service != ''
    end

    def respond_with(stuff)
      @client.print stuff << LNBK unless stuff.nil? or @client.nil? or @client.closed?
    end

    def parse(request)
      return if request.nil?
      command = request[0, 4].downcase.strip
      contents = request.split
      message = contents[1..contents.length]
      case command
        when *CMDS
          __send__ command, message
        else
          respond_with("500 Unknown command")
      end
    end

    def user(stuff = '')
      '331 send your password'
    end

    def pass(stuff = '')
      '<PASSWORD>'
    end
  end
end<commit_msg>Remove unused thread killing code<commit_after>require 'socket'
require "thread"

module FakeFtp
  class Server

    attr_accessor :directory, :port

    CMDS = %w[user pass]
    LNBK = "\r\n"

    def initialize(port = 21)
      self.port = port
      @connection = nil
      if self.is_running?
        raise "Port in use: #{port}"
      end
    end

    def start
      @status = :starting
      @server = ::TCPServer.new('127.0.0.1', port)
      @thread = Thread.new do
        begin
          while @status != :closed
            @client = @server.accept
            respond_with('200 Can has FTP?')
            @connection = Thread.new(@client) do |socket|
              parse(socket.gets)
            end
          end
        end
      end
    end

    def stop
      @status = :closed
      @thread = nil
      @server.close
      @server = nil
    end

    def is_running?
      service = `lsof -w -n -i tcp:#{port}`
      !service.nil? && service != ''
    end

    def respond_with(stuff)
      @client.print stuff << LNBK unless stuff.nil? or @client.nil? or @client.closed?
    end

    def parse(request)
      return if request.nil?
      command = request[0, 4].downcase.strip
      contents = request.split
      message = contents[1..contents.length]
      case command
        when *CMDS
          __send__ command, message
        else
          respond_with("500 Unknown command")
      end
    end

    def user(stuff = '')
      '<PASSWORD>'
    end

    def pass(stuff = '')
      '<PASSWORD>'
    end
  end
end
{'fraction_non_alphanumeric': 0.10383889238514789, 'fraction_numerical': 0.011642542479546885, 'mean_word_length': 1.7358003442340793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1642987', 'n_tokens_mistral': 1008, 'n_tokens_neox': 956, 'n_words': 274}